Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 260
Cornelius Roemer Avatar asked Nov 19 '25 04:11

Cornelius Roemer


1 Answers

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)
like image 162
Cornelius Roemer Avatar answered Nov 21 '25 18:11

Cornelius Roemer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!