mercredi 3 août 2016

drawing gaussian random variables using scipy erfinv

I would like to draw npts random variables distributed as a gaussian with mean mu and dispersion sigma. I know how to do this in Numpy:

x = np.random.normal(loc=mu, scale=sigma, size=npts)
print(np.std(x), np.mean(x))
0.1998, 0.3997

This should also be possible to do using scipy.special.erfinv via inverse transforms, beginning from a uniform distribution:

u = np.random.uniform(0, 1, npts)

However, I can't figure out how to get the scaling correct. Has anyone done this before?




Aucun commentaire:

Enregistrer un commentaire