Python中的概率分布函数 [英] Probability distribution function in Python
问题描述
我知道如何在Python中创建直方图,但我想这是概率密度分布.
I know how to create an histogram in Python, but I would like that it is the probability density distribution.
让我们从我的例子开始.我有一个数组d
,具有500000个元素.通过以下代码,我正在构建一个简单的直方图,告诉我每个仓之间有数组d
的元素多少.
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')
问题在于这不是我想要的情节.我想拥有我的数组d
的概率分布函数.与其让我的数组中每个bin中的元素数量不同,我不希望它们出现在该bin中.我尝试使用normed = True进行尝试,但是由于我的存储箱中的对数空间相同,因此似乎无法正常工作.
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.
推荐答案
目前尚不清楚您的hist
函数是什么.如果您使用的是NumPy的histogram
,请尝试设置density=True
.参见 http://docs.scipy.org/doc/numpy/reference/generation/numpy.histogram.html .
It's not clear what your hist
function is. If you're using NumPy's histogram
, try setting density=True
. See http://docs.scipy.org/doc/numpy/reference/generated/numpy.histogram.html .
这篇关于Python中的概率分布函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!