简体   繁体   中英

How do you draw random numbers from a given scipy random distribution?

I'm trying to generate random numbers from a given scipy stats random distribution, in my case a negative binomial distribution.

The documentation isn't entirely clear to me. Unfortunately, the documentation is a bit sparse: https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.nbinom.html

This should be really simple.

The relevant method is rvs which stands for random variates.

You can generate a single random number drawn from a negative binomial distribution like this:

import scipy.stats
scipy.stats.nbinom.rvs(1,0.5) # returns 2 (or other random integer between 0 and +inf)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM