You can download this code by clicking the button below.
This code is now available for download.
This function generates a random matrix of specified size with random values from a specified distribution.
Technology Stack : NumPy
Code Type : Function
Code Difficulty : Intermediate
import numpy as np
def random_matrix_row_cols(arg1, arg2, arg3):
# Generate a random matrix with specified number of rows and columns
# and fill it with random values from a specified distribution.
rows, cols = arg1, arg2
distribution = arg3 # 'uniform', 'normal', or 'poisson'
if distribution == 'uniform':
return np.random.uniform(size=(rows, cols))
elif distribution == 'normal':
return np.random.normal(size=(rows, cols))
elif distribution == 'poisson':
return np.random.poisson(size=(rows, cols))
else:
raise ValueError("Invalid distribution type. Choose 'uniform', 'normal', or 'poisson'.")