原文:https://docs.scipy.org/doc/numpy/reference/generated/numpy.percentile.html
校对:(虚位以待)
numpy.percentile(a, q, axis=None, out=None, overwrite_input=False, interpolation='linear', keepdims=False)[source]沿指定轴计算数据的第q个百分位数。
返回数组元素的第q个百分位数。
| 参数: | a:array_like
q:浮动范围为[0,100](或浮点数)
axis:{int,int,None},可选
out:ndarray,可选
overwrite_input:bool,可选
插值:{'linear','lower','higher','midpoint','nearest'}
keepdims:bool,可选
|
|---|---|
| 返回: | 百分位:标量或ndarray
|
也可以看看
笔记
Given a vector V of length N, the q-th percentile of V is the value q/100 of the way from the mimumum to the maximum in in a sorted copy of V. The values and distances of the two nearest neighbors as well as the interpolation parameter will determine the percentile if the normalized ranking does not match the location of q exactly. 如果q=50,则该函数与中值相同,如果q=0与最小值相同,并且如果q=100
例子
>>> a = np.array([[10, 7, 4], [3, 2, 1]])
>>> a
array([[10, 7, 4],
[ 3, 2, 1]])
>>> np.percentile(a, 50)
3.5
>>> np.percentile(a, 50, axis=0)
array([[ 6.5, 4.5, 2.5]])
>>> np.percentile(a, 50, axis=1)
array([ 7., 2.])
>>> np.percentile(a, 50, axis=1, keepdims=True)
array([[ 7.],
[ 2.]])
>>> m = np.percentile(a, 50, axis=0)
>>> out = np.zeros_like(m)
>>> np.percentile(a, 50, axis=0, out=out)
array([[ 6.5, 4.5, 2.5]])
>>> m
array([[ 6.5, 4.5, 2.5]])
>>> b = a.copy()
>>> np.percentile(b, 50, axis=1, overwrite_input=True)
array([ 7., 2.])
>>> assert not np.all(a == b)