本文共 636 字,大约阅读时间需要 2 分钟。
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?
解决方案#!/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.
转载地址:https://blog.csdn.net/weixin_39603778/article/details/118791645 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!