Code
Code
# a. Compute the mean, standard deviation, and variance of a two-dimensional random integer
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 then reshape it into an n x m array, where n and m are user inputs given at the run ti
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
1
print("Shape of the Array:")
print(shape_b)
print("Type of the Array:")
print(type_b)
print("Data Type of the Array:")
print(dtype_b)
print("Reshaped Array (n x m):")
print(array_b_reshaped)
# 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))
2
print(array_d3)
print("Array4 (Array3 - Array2):")
print(array_d4)
print("Array5 (2 * Array1):")
print(array_d5)
print("Covariance between Array1 and Array4:")
print(covariance)
print("Correlation between Array1 and Array5:")
print(correlation)
# 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