原文:https://docs.scipy.org/doc/numpy/reference/generated/numpy.ma.median.html
校对:(虚位以待)
numpy.ma.
median
(a, axis=None, out=None, overwrite_input=False, keepdims=False)[source]计算沿指定轴的中值。
返回数组元素的中位数。
参数: | a:array_like
axis:int,可选
out:ndarray,可选
overwrite_input:bool,可选
keepdims:bool,可选
|
---|---|
返回: | median:ndarray
|
也可以看看
笔记
Given a vector V
with N
non masked values, the median of V
is the middle value of a sorted copy of V
(Vs
) - i.e. Vs[(N-1)/2]
, when N
is odd, or {Vs[N/2 - 1] + Vs[N/2]}/2
when N
is even.
例子
>>> x = np.ma.array(np.arange(8), mask=[0]*4 + [1]*4)
>>> np.ma.median(x)
1.5
>>> x = np.ma.array(np.arange(10).reshape(2, 5), mask=[0]*6 + [1]*4)
>>> np.ma.median(x)
2.5
>>> np.ma.median(x, axis=-1, overwrite_input=True)
masked_array(data = [ 2. 5.],
mask = False,
fill_value = 1e+20)