I have the log-normal standard deviation and the mean that I want to use to sample from a log-normal distribution in Python. However after I do the sampling and compute the arithmetic mean and standard deviation I don't get the same values that plugged in. This only happens when the mean is too small, but for my case I have to work with this exact mean. Any idea on how to solve this will be greatly appreciated.
here's the code :
import numpy as np
import scipy.stats as stats
from statistics import mean
import matplotlib.pyplot as plt
import scipy.stats as stats
from math import exp
N=1000000
m = 1.75917e-7
siglog = 1.510297984
sigma= np.sqrt(np.log(1 + (siglog/m)**2)) #normal std
mu= (np.log(m) - sigma**2 / 2) #normal mean
f = stats.lognorm.rvs(sigma, loc=0, scale=exp(mu), size=N)
print(mean(f), np.std(f))
I get this result : 2.6542845542733312e-08 6.413511018978618e-06 which is very different from siglog and m.
np.exp
,np.mean
andnp.std
. $\endgroup$