使用scipy.stats.binom.cdf的二项分布CDF [英] Binomial distribution CDF using scipy.stats.binom.cdf

查看:191
本文介绍了使用scipy.stats.binom.cdf的二项分布CDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在下面的代码中使用了二项分布CDF(通过使用scipy.stats.binom.cdf)来估算在100次抛掷中,k头不超过k个的概率,其中k = 0、10、20、30,40、50、60、70、80、90、100.然后我尝试使用 hist()对其进行绘制.

I wrote below code to use binomial distribution CDF (by using scipy.stats.binom.cdf) to estimate the probability of having NO MORE THAN k heads out of 100 tosses, where k = 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100. and then I tried to plot it using hist().

import scipy
import matplotlib.pyplot as plt
def binomcdf():
    p = 0.5
    n = 100
    x = 0
    for a in range(10):
        print(scipy.stats.binom.cdf(x, n, p))
        x += 10

plt.hist(binomcdf())
plt.show()

但是我不知道为什么我的情节返回空白,并且收到以下错误消息,任何人都可以帮忙!

but I don't know why my plot returns empty, and I receive below error, can anyone help please!

TypeError:"NoneType"对象不可迭代

TypeError: 'NoneType' object is not iterable

推荐答案

我将x和每个关联x的对应cdf输出保存到列表中,然后返回该列表.然后使用列表中的数据进行绘制.

I would save x and the corresponding cdf output for each associated x to a list, then return that list. Then use the data in the list to make plot.

这篇关于使用scipy.stats.binom.cdf的二项分布CDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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