有没有人有使用 scipy.stats.distributions 的示例代码? [英] Does anyone have example code of using scipy.stats.distributions?

查看:42
本文介绍了有没有人有使用 scipy.stats.distributions 的示例代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力弄清楚如何使用 scipy.distributions 包,想知道是否有人可以为我发布一些示例代码.它似乎可以做我需要的一切,我只是不知道如何使用它.

我需要生成两个分布,一个对数正态分布和一个泊松分布.我知道每个的方差和 lambda.

资源链接也能正常工作.

解决方案

我假设您指的是 scipy.stats 中的分布.要创建分布,请生成随机变量并计算 pdf:

Python 2.5.1(r251:54863,2008 年 2 月 4 日,21:48:13)[GCC 4.0.1 (Apple Inc. build 5465)] 在达尔文上输入帮助"、版权"、信用"或许可"以了解更多信息.

<预><代码>>>>从 scipy.stats 导入泊松,lognorm>>>myShape = 5;myMu=10>>>ln = lognorm(myShape)>>>p = 泊松(myMu)>>>ln.rvs((10,)) #从ln生成10个RV数组([ 2.09164812e+00, 3.29062874e-01, 1.22453941e-03,3.80101527e+02、7.67464002e-02、2.53530952e+01、1.41850880e+03、8.36347923e+03、8.69209870e+03、1.64317413e-01])>>>p.rvs((10,)) #从p生成10个RV数组([ 8, 9, 7, 12, 6, 13, 11, 11, 10, 8])>>>ln.pdf(3) #lognorm PDF at x=3数组(0.02596183475208955)

其他方法(以及 scipy.stats 文档的其余部分)可以在新的 SciPy 文档 站点.

I am struggling to figure out how to use the scipy.distributions package and wondered if anyone could post some example code for me. It appears to do everything I need, I just can't figure out how to use it.

I need to generate two distributions, one log-normal and one poisson. I know the variance and lambda for each.

Links to resources would work just as well.

解决方案

I assume you mean the distributions in scipy.stats. To create a distribution, generate random variates and calculate the pdf:

Python 2.5.1 (r251:54863, Feb 4 2008, 21:48:13) [GCC 4.0.1 (Apple Inc. build 5465)] on darwin Type "help", "copyright", "credits" or "license" for more information.

>>> from scipy.stats import poisson, lognorm
>>> myShape = 5;myMu=10
>>> ln = lognorm(myShape)
>>> p = poisson(myMu)
>>> ln.rvs((10,)) #generate 10 RVs from ln
array([  2.09164812e+00,   3.29062874e-01,   1.22453941e-03,
         3.80101527e+02,   7.67464002e-02,   2.53530952e+01,
         1.41850880e+03,   8.36347923e+03,   8.69209870e+03,
         1.64317413e-01])
>>> p.rvs((10,)) #generate 10 RVs from p
array([ 8,  9,  7, 12,  6, 13, 11, 11, 10,  8])
>>> ln.pdf(3) #lognorm PDF at x=3
array(0.02596183475208955)

Other methods (and the rest of the scipy.stats documentation) can be found at the new SciPy documentation site.

这篇关于有没有人有使用 scipy.stats.distributions 的示例代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆