【发布时间】:2012-04-06 13:13:16
【问题描述】:
我有 1000 个大数,随机分布在 37231 到 56661 的范围内。
我正在尝试使用stats.gaussian_kde,但有些东西不起作用。
(可能是因为我对统计的了解不够?)。
代码如下:
from scipy import stats.gaussian_kde
import matplotlib.pyplot as plt
# 'data' is a 1D array that contains the initial numbers 37231 to 56661
xmin = min(data)
xmax = max(data)
# get evenly distributed numbers for X axis.
x = linspace(xmin, xmax, 1000) # get 1000 points on x axis
nPoints = len(x)
# get actual kernel density.
density = gaussian_kde(data)
y = density(x)
# print the output data
for i in range(nPoints):
print "%s %s" % (x[i], y[i])
plt.plot(x, density(x))
plt.show()
在打印输出中,我在第 1 列中得到 x 值,在第 2 列中得到零。 该图显示一条平线。
我根本找不到解决方案。 我尝试了非常广泛的 X-es,结果相同。
有什么问题?我究竟做错了什么? 大数字可能是原因吗?
【问题讨论】:
-
注意顶部附近的格式错误;您可以选择所有代码并点击
{}按钮在每行之前添加必要的四个空格。 -
@sarnold,对不起,您指的是哪个错误?我实际上使用了那个 {} 按钮,至少在我的 Mac 上格式看起来不错。 (我是这里的新手,但我提前为这个错误道歉)
-
@Proteos:看第一行,从“from scipy import..”开始。它没有标记为代码。
-
哈!这将教会我在不查看源代码的情况下提供建议;您必须在源代码之前留一个空行。这有点傻,但你是对的,代码都在那里......
标签: python statistics matplotlib scipy