python的百分位函数 numpy 百分位数( 二 )


def percentile(N, P):
"""
Find the percentile of a list of values
@parameter N - A list of values. N must be sorted.
@parameter P - A float value from 0.0 to 1.0
@return - The percentile of the values.
"""
n = int(round(P * len(N) + 0.5))
return N[n-1]
# A = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
# B = (15, 20, 35, 40, 50)
#
# print percentile(A, P=0.3)
# 4
# print percentile(A, P=0.8)
# 9
【python的百分位函数 numpy 百分位数】# print percentile(B, P=0.3)
# 20
# print percentile(B, P=0.8)
# 50
如果您宁愿从处于或低于该值的百分之P被发现所提供的列表中获得的价值,这个简单的修改:
def percentile(N, P):
n = int(round(P * len(N) + 0.5))
if n1:
return N[n-2]
else:
return 0
6.
numpy.percentile
在那里我很想念?
7.
size=len(mylist)
p5=mylist[math.ceil((size*5)/100)-1]
p25=mylist[math.ceil((size*25)/100)-1]
p50=mylist[math.ceil((size*50)/100)-1]
p75=mylist[math.ceil((size*75)/100)-1]
p95=mylist[math.ceil((size*95)/100)-1]
关于python的百分位函数和numpy 百分位数的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。

推荐阅读