原文:https://docs.scipy.org/doc/numpy/reference/generated/numpy.nanmedian.html
校对:(虚位以待)
numpy.
nanmedian
(a, axis=None, out=None, overwrite_input=False, keepdims=<class numpy._globals._NoValue>)[source]沿着指定轴计算中值,而忽略NaN。
返回数组元素的中位数。
版本1.9.0中的新功能。
参数: | a:array_like
axis:{int,int,None},可选
out:ndarray,可选
overwrite_input:bool,可选 keepdims:bool,可选 |
---|---|
返回: | median:ndarray
|
也可以看看
笔记
Given a vector V
of length N
, the median of V
is the middle value of a sorted copy of V
, V_sorted
- i.e., V_sorted[(N-1)/2]
, when N
is odd and the average of the two middle values of V_sorted
when N
is even.
例子
>>> a = np.array([[10.0, 7, 4], [3, 2, 1]])
>>> a[0, 1] = np.nan
>>> a
array([[ 10., nan, 4.],
[ 3., 2., 1.]])
>>> np.median(a)
nan
>>> np.nanmedian(a)
3.0
>>> np.nanmedian(a, axis=0)
array([ 6.5, 2., 2.5])
>>> np.median(a, axis=1)
array([ 7., 2.])
>>> b = a.copy()
>>> np.nanmedian(b, axis=1, overwrite_input=True)
array([ 7., 2.])
>>> assert not np.all(a==b)
>>> b = a.copy()
>>> np.nanmedian(b, axis=None, overwrite_input=True)
3.0
>>> assert not np.all(a==b)