Movatterモバイル変換


[0]ホーム

URL:


SciPy

numpy.median

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

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

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

Axis or axes along which the medians are computed. The defaultis to compute the median along a flattened version of the array.A sequence of axes is supported since version 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 arraya forcalculations. The input array will be modified by the call tomedian. This will save memory when you do not need to preservethe contents of the input array. Treat the input as undefined,but it will probably be fully or partially sorted. Default isFalse. Ifoverwrite_input isTrue anda is not already anndarray, an error will be raised.

keepdims : bool, optional

If this is set to True, the axes which are reduced are leftin the result as dimensions with size one. With this option,the result will broadcast correctly against the originalarr.

New in version 1.9.0.

Returns:

median : ndarray

A new array holding the result. If the input contains integersor floats smaller thanfloat64, then the output data-type isnp.float64. Otherwise, the data-type of the output is thesame as that of the input. Ifout is specified, that array isreturned instead.

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)

Previous topic

numpy.nanpercentile

Next topic

numpy.average

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

[8]ページ先頭

©2009-2025 Movatter.jp