在numpy阵列中找到每个数据点的百分位数

发布于 2025-01-23 05:00:40 字数 483 浏览 0 评论 0 原文

我有以下代码行:

threshold_value = numpy.percentile(a, q)

其中 a 是我的数据, q 设置为95,我们说。

让我们说,如果我将 q 更改为90,我将获得不同的阈值值。

对于 a 中的每个数据点,我想计算Q的值将产生 threshold_value 等于a的值。因此,我感兴趣的是 a 中的一个数据点低于阈值_value,但是我希望百分位数值确切查看它在哪里。当我有一个测试数据集时,我将每个值与阈值值进行比较,以查看是否超过它。因此,我不想给出AQ值,我想被告知数据点的Q值是什么。

因此,我想要函数,也许 a_percentile = function(a),其中a_percentile是对百分位数的原始数据值的转换。

I have the following line of code:

threshold_value = numpy.percentile(a, q)

where a is my data and q is set at 95 let us say.

And let us say that if I changed q to be 90, I would get a different threshold value.

Well for each data point in a, I would like to calculate what value of q would yield threshold_value equal to a. So what I am interested in is perhaps a data point in a is below the threshold_value, but I want a percentile value to see exactly where is it at. When I have a test dataset, I compare each value to the threshold value to see if it exceeds it or not. So I don't want to give a q value, I want to be told what the q value is for a data point.

So I want function maybe a_percentile = function(a) where a_percentile is a transformation of the original data value to the percentile.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酷炫老祖宗 2025-01-30 05:00:40

使用scipy.stats.percentileofscore

import numpy as np
from scipy.stats import percentileofscore
a = np.linspace(0, 10, 10)
[percentileofscore(a, i, kind='strict') for i in a]

输出:输出:

[0.0, 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0, 90.0]

Use scipy.stats.percentileofscore https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.percentileofscore.html:

import numpy as np
from scipy.stats import percentileofscore
a = np.linspace(0, 10, 10)
[percentileofscore(a, i, kind='strict') for i in a]

Output:

[0.0, 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0, 90.0]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文