numpy.nanmedian(a,axis=None,out=None,overwrite_input=False,keepdims=<class numpy._globals._NoValue>)[source]¶Compute the median along the specified axis, while ignoring NaNs.
Returns the median of the array elements.
New in version 1.9.0.
| Parameters: | a : array_like
axis : {int, sequence of int, None}, optional
out : ndarray, optional
overwrite_input : bool, optional
keepdims : bool, optional
|
|---|---|
| Returns: | median : ndarray
|
See also
Notes
Given a vectorV of lengthN, the median ofV is themiddle value of a sorted copy ofV,V_sorted - i.e.,V_sorted[(N-1)/2], whenN is odd and the average of the twomiddle values ofV_sorted whenN is even.
Examples
>>>a=np.array([[10.0,7,4],[3,2,1]])>>>a[0,1]=np.nan>>>aarray([[ 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.])>>>assertnotnp.all(a==b)>>>b=a.copy()>>>np.nanmedian(b,axis=None,overwrite_input=True)3.0>>>assertnotnp.all(a==b)