numpy.ma.median(a,axis=None,out=None,overwrite_input=False,keepdims=False)[source]¶Compute the median along the specified axis.
Returns the median of the array elements.
| Parameters: |
|
|---|---|
| Returns: |
|
See also
Notes
Given a vectorV withN non masked values, the median ofVis the middle value of a sorted copy ofV (Vs) - i.e.Vs[(N-1)/2], whenN is odd, or{Vs[N/2-1]+Vs[N/2]}/2whenN is even.
Examples
>>>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)