On Thu, Jul 7, 2011 at 9:26 AM, Wolfgang Kerzendorf <[email protected]> wrote: > Hi all, > > Is there an way to get random numbers from an arbitrary distribution > already built-in to numpy. I am interested to do that for a black body > distribution
What's a black body distributions? From a quick look at Wikipedia it might be planck, which is available in scipy.stats. A new distribution can be generated by subclassing scipy.stats.distributions.rv_continuous It has a generic random variable generator using the quantile function, ppf. If the ppf is available, then this is fast. If only the pdf is given, generating random variables is sloooow. (cdf is calculated by integrate.quad, ppf is generated from cdf with optimize.fsolve) Some distributions can be generated by a transformation of variables, which can also be very fast. Nothing else to generate arbitrary random variables is available in numpy or scipy. (I just started to read a paper that uses a piecewise polynomial approximation to the ppf that should work for fast generation of random variables when only the pdf is given.) Josef > > Thanks > Wolfgang > _______________________________________________ > NumPy-Discussion mailing list > [email protected] > http://mail.scipy.org/mailman/listinfo/numpy-discussion > _______________________________________________ NumPy-Discussion mailing list [email protected] http://mail.scipy.org/mailman/listinfo/numpy-discussion
