Numpy array with different standard deviation per row
问题 I'd like to get an NxM matrix where numbers in each row are random samples generated from different normal distributions(same mean but different standard deviations). The following code works: import numpy as np mean = 0.0 # same mean stds = [1.0, 2.0, 3.0] # different stds matrix = np.random.random((3,10)) for i,std in enumerate(stds): matrix[i] = np.random.normal(mean, std, matrix.shape[1]) However, this code is not quite efficient as there is a for loop involved. Is there a faster way to