Movatterモバイル変換


[0]ホーム

URL:


SciPy

numpy.percentile

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

Input array or object that can be converted to an array.

q : float in range of [0,100] (or sequence of floats)

Percentile to compute, which must be between 0 and 100 inclusive.

axis : {int, sequence of int, None}, optional

Axis or axes along which the percentiles are computed. Thedefault is to compute the percentile(s) along a flattenedversion of the array. A sequence of axes is supported sinceversion 1.9.0.

out : ndarray, optional

Alternative output array in which to place the result. It musthave the same shape and buffer length as the expected output,but the type (of the output) will be cast if necessary.

overwrite_input : bool, optional

If True, then allow use of memory of input arrayacalculations. The input array will be modified by the call topercentile. This will save memory when you do not need topreserve the contents of the input array. In this case youshould not make any assumptions about the contents of the inputa after this function completes – treat it as undefined.Default is False. Ifa is not already an array, this parameterwill have no effect asa will be converted to an arrayinternally regardless of the value of this parameter.

interpolation : {‘linear’, ‘lower’, ‘higher’, ‘midpoint’, ‘nearest’}

This optional parameter specifies the interpolation method touse when the desired quantile lies between two data pointsi<j:

  • linear:i+(j-i)*fraction, wherefractionis the fractional part of the index surrounded byiandj.
  • lower:i.
  • higher:j.
  • nearest:i orj, whichever is nearest.
  • midpoint:(i+j)/2.

New in version 1.9.0.

keepdims : bool, optional

If this is set to True, the axes which are reduced are left inthe result as dimensions with size one. With this option, theresult will broadcast correctly against the original arraya.

New in version 1.9.0.

Returns:

percentile : scalar or ndarray

Ifq is a single percentile andaxis=None, then the resultis a scalar. If multiple percentiles are given, first axis ofthe result corresponds to the percentiles. The other axes arethe axes that remain after the reduction ofa. If the inputcontains integers or floats smaller thanfloat64, the outputdata-type isfloat64. Otherwise, the output data-type is thesame as that of the input. Ifout is specified, that array isreturned instead.

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)

Previous topic

numpy.ptp

Next topic

numpy.nanpercentile

  • © Copyright 2008-2009, The Scipy community.
  • Last updated on Jun 10, 2017.
  • Created usingSphinx 1.5.3.

[8]ページ先頭

©2009-2025 Movatter.jp