bundles / numpy 2.5.0.dev0+git20251130.2de293a / numpy / ma / extras / median
function
numpy.ma.extras:median
source: build-install/usr/lib/python3.14/site-packages/numpy/ma/extras.py :678
Signature
def median ( a , axis = None , out = None , overwrite_input = False , keepdims = False ) Summary
Compute the median along the specified axis.
Extended Summary
Returns the median of the array elements.
Parameters
a: array_likeInput array or object that can be converted to an array.
axis: int, optionalAxis along which the medians are computed. The default (None) is to compute the median along a flattened version of the array.
out: ndarray, optionalAlternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary.
overwrite_input: bool, optionalIf True, then allow use of memory of input array (a) for calculations. The input array will be modified by the call to median. This will save memory when you do not need to preserve the contents of the input array. Treat the input as undefined, but it will probably be fully or partially sorted. Default is False. Note that, if
overwrite_inputis True, and the input is not already an ndarray, an error will be raised.keepdims: bool, optionalIf this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array.
Returns
Notes
Given a vector V with N non masked values, the median of V is the middle value of a sorted copy of V (Vs) - i.e. Vs[(N-1)/2], when N is odd, or {Vs[N/2 - 1] + Vs[N/2]}/2 when N is even.
Examples
import numpy as np x = np.ma.array(np.arange(8), mask=[0]*4 + [1]*4)✓
np.ma.median(x)
✗x = np.ma.array(np.arange(10).reshape(2, 5), mask=[0]*6 + [1]*4)
✓np.ma.median(x)
✗np.ma.median(x, axis=-1, overwrite_input=True)
✓See also
Aliases
-
numpy.ma.median