scipy.stats没有属性“ counts”

时间:2018-09-11 08:03:35

标签: python scipy statistics

我想打印矢量的质量概率函数,所以我在pmf中使用函数scipy。这是我的代码:

import scipy.stats
import numpy as np
import matplotlib as plt

x=np.loadtxt("file")

counts,bins,bars=np.hist(x,bins=500,normed=1)

plt.plot(bins[:-1],scipy.stats.counts.pmf(bins[:-1])))
plt.show()

我收到错误

'Attribute error: module scipy.stats has no attribute 'counts'

谢谢您的回答。

2 个答案:

答案 0 :(得分:0)

import matplotlib as plt

更改为

import matplotlib.pyplot as plt

x=np.loadtxt("file")->我们的计算机上没有文件“ file”,请使用随机或其他简单方式为x生成数据。

counts,bins,bars=np.hist(x,bins=500,normed=1)

更改为

counts, bins, bars = plt.hist(x,bins=500,normed=1)

如果在

scipy.stats.counts.pmf(bins[:-1]))

您收到错误'Attribute error: module scipy.stats has no attribute 'counts',这不是错误。您要达到什么目标(即用通俗易懂的语言解释预期结果)?然后有人可以尝试提供帮助。

PS:我发布了此扩展注释,以作为代码等正确格式的答案。

答案 1 :(得分:0)

您想要的是

 scipy.stats.rv_discrete.pmf