我有以下代碼行:
threshold_value = numpy.percentile(a, q)
a我的資料在哪里,q我們說設定為 95。
讓我們說,如果我變成q90,我會得到一個不同的閾值。
那么對于 中的每個資料點a,我想計算 q 的什么值會產生threshold_value等于 a。所以我感興趣的可能是一個資料點a低于閾值,但我想要一個百分位值來查看它的確切位置。當我有一個測驗資料集時,我將每個值與閾值進行比較,看看它是否超過它。所以我不想給出 aq 值,我想被告知資料點的 q 值是多少。
所以我想要函式,a_percentile = function(a)其中 a_percentile 是將原始資料值轉換為百分位數。
uj5u.com熱心網友回復:
使用 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]
輸出:
[0.0, 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0, 90.0]
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/461740.html
上一篇:基于串列組合的numpy乘法
下一篇:映射陣列值的有效方法
