Movatterモバイル変換


[0]ホーム

URL:


SciPy

numpy.ma.median

numpy.ma.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, optional

Axis along which the medians are computed. The default (None) isto compute the median along a flattened version of the array.

out:ndarray, optional

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

overwrite_input:bool, optional

If True, then allow use of memory of input array (a) 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. Note that, ifoverwrite_input is True, and the inputis 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 input array.

New in version 1.10.0.

Returns:
median:ndarray

A new array holding the result is returned unless out isspecified, in which case a reference to out is returned.Return data-type isfloat64 for integers and floats smaller thanfloat64, or the input data-type, otherwise.

See also

mean

Notes

Given a vectorV withN non masked values, the median ofVis the middle value of a sorted copy ofV (Vs) - i.e.Vs[(N-1)/2], whenN is odd, or{Vs[N/2-1]+Vs[N/2]}/2whenN is even.

Examples

>>>x=np.ma.array(np.arange(8),mask=[0]*4+[1]*4)>>>np.ma.median(x)1.5
>>>x=np.ma.array(np.arange(10).reshape(2,5),mask=[0]*6+[1]*4)>>>np.ma.median(x)2.5>>>np.ma.median(x,axis=-1,overwrite_input=True)masked_array(data = [ 2.  5.],             mask = False,       fill_value = 1e+20)

Previous topic

numpy.ma.mean

Next topic

numpy.ma.power

Quick search

  • © Copyright 2008-2018, The SciPy community.
  • Last updated on Jul 24, 2018.
  • Created usingSphinx 1.6.6.

[8]ページ先頭

©2009-2025 Movatter.jp