有没有一种方便的方法来计算序列或单维numpy数组的百分位数?
我正在寻找类似于Excel的百分位函数的东西.
我查看了NumPy的统计参考,但是找不到这个.我能找到的只是中位数(第50百分位数),但不是更具体的东西.
我想创建一个函数,它将(有序)列表作为其参数,并输出一个包含每个元素的相应百分位数的列表.
例如,fn([1,2,3,4,17])退货[0.0, 0.25, 0.50, 0.75, 1.00].
任何人都可以请:
我目前的代码:
def median(mylist):
length = len(mylist)
if not length % 2:
return (mylist[length / 2] + mylist[length / 2 - 1]) / 2.0
return mylist[length / 2]
###############################################################################
# PERCENTILE FUNCTION
###############################################################################
def percentile(x):
"""
Find the correspoding percentile of each value relative to a list of values.
where x is the list of values
Input list should already be sorted!
"""
# sort the input list …Run Code Online (Sandbox Code Playgroud)