概率密度函数 numpy 直方图/scipy 统计信息 [英] Probability density function numpy histogram/scipy stats

查看:65
本文介绍了概率密度函数 numpy 直方图/scipy 统计信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有数组a=range(10).使用 numpy.histogram:

hist,bins=numpy.histogram(a,bins=(np.max(a)-np.min(a))/1, range=np.min(a),np.max(a)),density=True)

根据numpy教程:

如果 density=True,结果是 bin 处概率密度函数的值,归一化使得范围内的积分为 1.

If density=True, the result is the value of the probability density function at the bin, normalized such that the integral over the range is 1.

结果是:

array([ 0.1,  0.1,  0.1,  0.1,  0.1,  0.1,  0.1,  0.1,  0.2])

我尝试使用 scipy.stats 来做同样的事情:

I try to do the same using scipy.stats:

mean = np.mean(a)
sigma = np.std(a)
norm.pdf(a, mean, sigma)

然而结果是不同的:

array([ 0.04070852,  0.06610774,  0.09509936,  0.12118842,  0.13680528,0.13680528,  0.12118842,  0.09509936,  0.06610774,  0.04070852])

我想知道为什么.

更新:我想提出一个更笼统的问题.我们如何在不使用 numpy.histogram for density=True 的情况下获得数组的概率密度函数?

Update:I would like to set a more general question. How can we have the probability density function of an array without using numpy.histogram for density=True ?

推荐答案

如果密度=True,结果就是概率密度的值函数在 bin,归一化,使得积分在范围为 1.

If density=True, the result is the value of the probability density function at the bin, normalized such that the integral over the range is 1.

那里的标准化"并不意味着它将使用正态分布进行转换.它只是说 bin 中的每个值将除以条目总数,以便总密度等于 1.

The "normalized" there does not mean that it will be transformed using a Normal Distribution. It simply says that each value in the bin will be divided by the total number of entries so that the total density would be equal to 1.

这篇关于概率密度函数 numpy 直方图/scipy 统计信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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