[Numpy-discussion] Behavior of numpy.random.exponential

Yves Frederix yves.frederix at gmail.com
Fri Mar 27 07:49:53 EDT 2009


Hi,

I noticed a problem with numpy.random.exponential. Apparently, the
samples generated by numpy.random.exponential(scale=scale) follow the
distribution f(x)=1/scale*exp(-x/scale) (and not
f(x)=scale*exp(-x*scale) as stated by the docstring).

The script below illustrates this.

--
import numpy as N
import pylab as pl

print N.__version__

pl.figure()

lamda = 2.

noise_modulus = N.random.exponential(scale=lamda,\
    size=(100000,))
#noise_modulus = -N.log(N.random.uniform(size=(100000,)))/lamda # this works

y_hist, x_hist = N.histogram(noise_modulus, bins=51,\
        normed=True, new=True)
x_pl = N.linspace(0, x_hist.max())
pl.semilogy(x_hist[0:-1], y_hist, label='Empirical, lambda=%s' % lamda)
pl.semilogy(x_pl, lamda * N.exp(-x_pl*lamda), ':', \
        label='exact, lambda=%s' % lamda)
pl.semilogy(x_pl, 1./lamda * N.exp(-x_pl*1./lamda), ':', \
        label='exact, lambda=1/%s' % lamda)

pl.legend(loc='best')
pl.show()

--

Could this be a bug? I also checked with the latest svn version:

In [1]: import numpy; numpy.__version__
Out[1]: '1.4.0.dev6731'

Best,
YVES



More information about the NumPy-Discussion mailing list