numpy.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: | 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 - ie.,V_sorted[(N-1)/2], whenN is odd, and the average of thetwo middle values ofV_sorted whenN is even.
Examples
>>>a=np.array([[10,7,4],[3,2,1]])>>>aarray([[10, 7, 4], [ 3, 2, 1]])>>>np.median(a)3.5>>>np.median(a,axis=0)array([ 6.5, 4.5, 2.5])>>>np.median(a,axis=1)array([ 7., 2.])>>>m=np.median(a,axis=0)>>>out=np.zeros_like(m)>>>np.median(a,axis=0,out=m)array([ 6.5, 4.5, 2.5])>>>marray([ 6.5, 4.5, 2.5])>>>b=a.copy()>>>np.median(b,axis=1,overwrite_input=True)array([ 7., 2.])>>>assertnotnp.all(a==b)>>>b=a.copy()>>>np.median(b,axis=None,overwrite_input=True)3.5>>>assertnotnp.all(a==b)