Reputation: 5271
Assume 3 matrices Mean, Variance, Sample all with the same dimensionality. Is there a 1 line solution to generate the Sample matrix in numpy such that:
Sample[i,j] is drawn from NormalDistribution(Mean[i,j], Variance[i,j])
Upvotes: 0
Views: 38
Reputation: 13218
Using linearity of mean and Var(aX +b) = a**2 Var(X):
Generate a centered and reduced 2D array with np.random.randn()
. Multiply pointwise by std (np.sqrt(variance)) and add (still pointwise) mean.
Upvotes: 2