Why does numpy.random.normal gives some negative value in the ndarray?

Question:

I know that the normal distribution is always greater than 0 for any chosen value of the mean and the standard deviation.

>> np.random.normal(scale=0.3, size=x.shape)
[ 0.15038925 -0.34161875 -0.07159422  0.41803414  0.39900799  0.10714512
  0.5770597  -0.16351734  0.00962916  0.03901677]

Here the mean is 0.0 and the standard deviation is 0.3. But some values in the ndarray are negative. Am I wrong in my interpretation that normal distribution curve is always positive?

Edit:
But using normpdf function in matlab always give an array of positive values which I guess is the probability density function (y axis). Whereas numpy.random.normal gives both positive and negative values (x axis). Now this is confusing.

Asked By: dlphehe

||

Answers:

Values generated from a Normal distribution does take negative value.

For example, for a mean 0 normal distribution. We need some positive values and negative values for the average value to be zero. Also, for the normal distribution with mean 0, it is equally likely to be positive or negative.

It actually take any real number with positive probability. You might be confused with the probability density function is always positive.

Answered By: Siong Thye Goh

Try to not expect probability mean as 0, as it makes no sense, you expecting your random event never to occur.
Try to use something like np.random.normal(0.5, 0.3, 1000) to express your normal probability distribution.

Also, take a closer look at the math of Normal Distribution to be able to construct your probability density functions easily.

Answered By: Platon

referencing to np.random.normal in "https://numpy.org/doc/stable/reference/random/generated/numpy.random.normal.html", the output is the sample (x), not the distribution (y). Therefore, the output can be negative.

Therefore, np.random.normal is used to do the sampling by following the normal distribution, not to randomly generate a probability value by following the normal distribution.

Answered By: Mingming Qiu