Python中的概率分布函数
我知道如何在 Python 中创建直方图,但我希望它是概率密度分布。
让我们从我的例子开始吧。我有一个数组 d
,大小为 500000 个元素。使用以下代码,我构建了一个简单的直方图,告诉我数组 d
的每个 bin 之间有多少个元素。
max_val=log10(max(d))
min_val=log10(min(d))
logspace = np.logspace(min_val, max_val, 50)
H=hist(select,bins=logspace,histtype='step')
问题是这个剧情不是我想要的。我想要我的数组d
的概率分布函数。我不想知道每个容器中的数组元素的数量,而是希望知道它们位于该容器中的概率。我尝试使用normed=True,但这似乎不起作用,因为我有同样对数间隔的垃圾箱。
I know how to create an histogram in Python, but I would like that it is the probability density distribution.
Let's start with my example. I have an array d
, with a size of 500000 elements. With the following code I am building a simple histogram telling me how many elements of my array d
are between every bin.
max_val=log10(max(d))
min_val=log10(min(d))
logspace = np.logspace(min_val, max_val, 50)
H=hist(select,bins=logspace,histtype='step')
The problem is that this plot is not what I want. I would like to have the probability distribution function of my array d
. Instead of having the number of elements of my array which are within every bins, I would like to have the probability of them being in that bin. I tried with normed=True, but that seems not working since I have bins which are equally logspaced.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
目前尚不清楚您的
hist
函数是什么。如果您使用 NumPy 的直方图
,请尝试设置密度=True
。请参阅http://docs.scipy.org/doc/numpy/参考/生成/numpy.histogram.html 。It's not clear what your
hist
function is. If you're using NumPy'shistogram
, try settingdensity=True
. See http://docs.scipy.org/doc/numpy/reference/generated/numpy.histogram.html .