原文:https://docs.scipy.org/doc/numpy/reference/generated/numpy.nanpercentile.html
校对:(虚位以待)
numpy.
nanpercentile
(a, q, axis=None, out=None, overwrite_input=False, interpolation='linear', keepdims=<class numpy._globals._NoValue>)[source]沿着指定轴计算数据的第q个百分位数,而忽略nan值。
返回数组元素的第q个百分位数。
版本1.9.0中的新功能。
参数: | 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[0][1] = np.nan
>>> a
array([[ 10., nan, 4.],
[ 3., 2., 1.]])
>>> np.percentile(a, 50)
nan
>>> np.nanpercentile(a, 50)
3.5
>>> np.nanpercentile(a, 50, axis=0)
array([ 6.5, 2., 2.5])
>>> np.nanpercentile(a, 50, axis=1, keepdims=True)
array([[ 7.],
[ 2.]])
>>> m = np.nanpercentile(a, 50, axis=0)
>>> out = np.zeros_like(m)
>>> np.nanpercentile(a, 50, axis=0, out=out)
array([ 6.5, 2., 2.5])
>>> m
array([ 6.5, 2. , 2.5])
>>> b = a.copy()
>>> np.nanpercentile(b, 50, axis=1, overwrite_input=True)
array([ 7., 2.])
>>> assert not np.all(a==b)