0

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])

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Completely forgot about the transformation between a standard normal and a normal distribution. Great!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.