numpy.percentile(a,q,axis=None,out=None,overwrite_input=False,interpolation='linear',keepdims=False)[source]¶Compute the qth percentile of the data along the specified axis.
Returns the qth percentile(s) of the array elements.
| Parameters: | a : array_like
q : float in range of [0,100] (or sequence of floats)
axis : {int, sequence of int, None}, optional
out : ndarray, optional
overwrite_input : bool, optional
interpolation : {‘linear’, ‘lower’, ‘higher’, ‘midpoint’, ‘nearest’}
keepdims : bool, optional
|
|---|---|
| Returns: | percentile : scalar or ndarray
|
See also
Notes
Given a vectorV of lengthN, theq-th percentile ofV is the valueq/100 of the way from the minimum to themaximum in a sorted copy ofV. The values and distances ofthe two nearest neighbors as well as theinterpolation parameterwill determine the percentile if the normalized ranking does notmatch the location ofq exactly. This function is the same asthe median ifq=50, the same as the minimum ifq=0 and thesame as the maximum ifq=100.
Examples
>>>a=np.array([[10,7,4],[3,2,1]])>>>aarray([[10, 7, 4], [ 3, 2, 1]])>>>np.percentile(a,50)3.5>>>np.percentile(a,50,axis=0)array([[ 6.5, 4.5, 2.5]])>>>np.percentile(a,50,axis=1)array([ 7., 2.])>>>np.percentile(a,50,axis=1,keepdims=True)array([[ 7.], [ 2.]])
>>>m=np.percentile(a,50,axis=0)>>>out=np.zeros_like(m)>>>np.percentile(a,50,axis=0,out=out)array([[ 6.5, 4.5, 2.5]])>>>marray([[ 6.5, 4.5, 2.5]])
>>>b=a.copy()>>>np.percentile(b,50,axis=1,overwrite_input=True)array([ 7., 2.])>>>assertnotnp.all(a==b)