[SciPy-user] Random number generation and scipy.stats

Anne Archibald peridot.faceted@gmail....
Thu Mar 8 10:16:48 CST 2007


scipy.stats defines a number of distribution objects (scipy.stats.chi2
represents the chi-squared distribution, for example). How useful
would it be to add a .generate(size=(1,)) method which generated
random numbers according to the distribution? There's practically no
extra effort involved for those functions which have a .ppf() method,
since that allows one to use the transformation method:

In [1]: import numpy, scipy.stats

In [2]: scipy.stats.chi2.ppf(numpy.random.rand(5),2)
Out[2]: array([ 3.19017391,  3.27772839,  3.44953492,  8.09066854,  0.29628122])

Maybe the simplicity makes it not worth implementing, but on the one
hand there may be distributions that allow much more efficient
generation, and on the other this may not occur to users...

Anne M. Archibald

More information about the SciPy-user mailing list