Code 2
Code 2
# a. Compute the mean, standard deviation, and variance of a two-dimensional random integer array along the second axis.
array_a = np.random.randint(0, 10, size=(3, 5))
mean_a = np.mean(array_a, axis=1)
std_dev_a = np.std(array_a, axis=1)
variance_a = np.var(array_a, axis=1)
# b. Create a 2-dimensional array of size m x n integer elements, also print the shape, type and data type of the array,
# and then reshape it into an n x m array, where n and m are user inputs given at the run time.
m = int(input("Enter the number of rows (m): "))
n = int(input("Enter the number of columns (n): "))
array_b = np.random.randint(0, 10, size=(m, n))
shape_b = array_b.shape
type_b = type(array_b)
dtype_b = array_b.dtype
# c. Test whether the elements of a given 1D array are zero, non-zero, and NaN.
# Record the indices of these elements in three separate arrays.
array_c = np.array([0, 1, 0, 3, np.nan, 5])
zero_indices = np.where(array_c == 0)[0]
nonzero_indices = np.where(array_c != 0)[0]
nan_indices = np.where(np.isnan(array_c))[0]
# d. Create three random arrays of the same size: Array1, Array2, and Array3.
# Subtract Array2 from Array3 and store in Array4.
# Create another array Array5 having two times the values in Array1.
# Find Covariance and Correlation of Array1 with Array4 and Array5 respectively.
array_d1 = np.random.randint(0, 10, size=(4, 4))
array_d2 = np.random.randint(0, 10, size=(4, 4))
array_d3 = np.random.randint(0, 10, size=(4, 4))
# e. Create two random arrays of the same size 10: Array1 and Array2.
array_e1 = np.random.randint(0, 10, size=10)
array_e2 = np.random.randint(0, 10, size=10)
Output