13

Are there any built-in libraries in Python or Numpy to generate random numbers based on various common distributions, such as:

  • Normal
  • Poisson
  • Exponential
  • Bernoulli

And various others?

Are there any such libraries with multi-variate distributions?

2 Answers 2

28
#!/usr/bin/env python
from scipy.stats import bernoulli,poisson,norm,expon

bernoulli, poisson, norm, expon and many others are documented here

print(norm.rvs(size=30))
print(bernoulli.rvs(.3,size=30))
print(poisson.rvs(1,2,size=30))
print(expon.rvs(5,size=30))

All the distributions defined in scipy.stats have a common interface to the pdf, cdf, rvs (random variates). More info here.

Sign up to request clarification or add additional context in comments.

3 Comments

Import soul. Damn you Python !
Your second link there says "Forbidden" ... "You don't have permission to access /~dkuhlman/scipy_course_01.html on this server." --- looks like linkrot
@Glen_b: I've changed the link to a cached version of the page.
5

The random module has tons of functions for generating random numbers in lots of way. Not sure it has multi-variate.

Numpy.random would be the next place to look.

1 Comment

I took the liberty of adding in a link to the documentation for random

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.