numpy.random.lognormal includes a parameter “mean” which is the “mean value of the underlying normal distribution.”
How is it possible that mean can be a negative value, or even zero, since a normal distribution with a mean of zero would include negative values? My understanding is that the log of a negative number is undefined, so I would think the underlying normal distribution should be prohibited from including negative values.
I ask because I need to randomly sample values from a lognormal distribution with a given mean and standard deviation. I’m converting the lognormal mean and lognormal std to the normal mean and normal std as described here, and I’m getting results, but I’m unclear how numpy.random.lognormal handles situations where the underlying normal distribution includes negative values.
for example,
print(np.random.lognormal(mean=-1, sigma=1, size=10))
produces
[0.40300944 1.09557872 0.05249852 0.09196479 0.0370128 4.09527677
2.07059534 3.33527883 0.81450692 0.97669691]
whereas I would expect it to raise an error.
3
From the docs (emphasis mine):
Draw samples from a log-normal distribution with specified mean, standard deviation, and array shape. Note that the mean and standard deviation are not the values for the distribution itself, but of the underlying normal distribution it is derived from.
np.random.lognormal(mean, sigma)
is equivalent to np.exp(np.random.normal(mean, sigma))
, including in how it interprets the mean
/ sigma
.
0