scipy.stats.percentileofscore(a, score, kind='rank')
函数可以帮助我们计算分数相对于分数列表的百分数等级。
假设x的百分位数为60%,则意味着a中80%的分数低于x。
参数:
arr :[数组]输入数组。
score :[int或float]与数组元素相比的得分。
kind :[可选]“等级”,“弱”,“严格”,“平均”。
结果:分数相对于数组元素的百分数。
代码1:
# percentileofscore
from scipy import stats
import numpy as np
# 1D array
arr = [20, 2, 7, 1, 7, 7, 34]
print("arr : ", arr)
print ("\nPercetile of 7 : ", stats.percentileofscore(arr, 7))
print ("\nPercetile of 34 : ", stats.percentileofscore(arr, 34))
print ("\nPercetile of 2 : ", stats.percentileofscore(arr, 2))
输出:
arr : [20, 2, 7, 1, 7, 7, 34]
Percetile of 7 : 57.1428571429
Percetile of 34 : 100.0
Percetile of 2 : 28.5714285714