I want to generate a normal (probability) distribution using numpy.random.normal()
, where the sum of the probabilities in a row (over all columns) must be 1.
I used the following code to generate a sample 4 by 3 probability matrix:
mu, sigma = 0.5, 0.20 # mean and standard deviation
np.random.seed(40)
sample_probability = np.random.normal(mu, sigma, size=(4,3))
but the sum of the probabilities in each row becomes larger than 1, which I don't want to have.
[[0.37849046 0.47477272 0.36307873]
[0.68574295 0.13111979 0.40659952]
[0.95849807 0.59776201 0.6420534 ]
[0.71110689 0.51081462 0.55159068]]
i.e. np.sum(sample_probability[0,:])
yields 1.216341905895543
, but I want to make it 1.
Would you please share your insights how I can customize numpy.random.normal()
so that it limits the distribution of probabilities in a row into 1?
Thanks.
[UPDATE] I went for manually normalizing each row, rather introducing the modifications in numpy.random.normal()
. Thanks to Mikhail and Frank.