MCPcopy Index your code
hub / github.com/numpy/numpy / median

Function median

numpy/ma/extras.py:678–753  ·  view source on GitHub ↗

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

(a, axis=None, out=None, overwrite_input=False, keepdims=False)

Source from the content-addressed store, hash-verified

676
677
678def median(a, axis=None, out=None, overwrite_input=False, keepdims=False):
679 """
680 Compute the median along the specified axis.
681
682 Returns the median of the array elements.
683
684 Parameters
685 ----------
686 a : array_like
687 Input array or object that can be converted to an array.
688 axis : int, optional
689 Axis along which the medians are computed. The default (None) is
690 to compute the median along a flattened version of the array.
691 out : ndarray, optional
692 Alternative output array in which to place the result. It must
693 have the same shape and buffer length as the expected output
694 but the type will be cast if necessary.
695 overwrite_input : bool, optional
696 If True, then allow use of memory of input array (a) for
697 calculations. The input array will be modified by the call to
698 median. This will save memory when you do not need to preserve
699 the contents of the input array. Treat the input as undefined,
700 but it will probably be fully or partially sorted. Default is
701 False. Note that, if `overwrite_input` is True, and the input
702 is not already an `ndarray`, an error will be raised.
703 keepdims : bool, optional
704 If this is set to True, the axes which are reduced are left
705 in the result as dimensions with size one. With this option,
706 the result will broadcast correctly against the input array.
707
708 Returns
709 -------
710 median : ndarray
711 A new array holding the result is returned unless out is
712 specified, in which case a reference to out is returned.
713 Return data-type is `float64` for integers and floats smaller than
714 `float64`, or the input data-type, otherwise.
715
716 See Also
717 --------
718 mean
719
720 Notes
721 -----
722 Given a vector ``V`` with ``N`` non masked values, the median of ``V``
723 is the middle value of a sorted copy of ``V`` (``Vs``) - i.e.
724 ``Vs[(N-1)/2]``, when ``N`` is odd, or ``{Vs[N/2 - 1] + Vs[N/2]}/2``
725 when ``N`` is even.
726
727 Examples
728 --------
729 >>> import numpy as np
730 >>> x = np.ma.array(np.arange(8), mask=[0]*4 + [1]*4)
731 >>> np.ma.median(x)
732 1.5
733
734 >>> x = np.ma.array(np.arange(10).reshape(2, 5), mask=[0]*6 + [1]*4)
735 >>> np.ma.median(x)

Callers 7

test_2dMethod · 0.90
test_2d_waxisMethod · 0.90
test_3dMethod · 0.90
test_neg_axisMethod · 0.90
test_out_1dMethod · 0.90
test_outMethod · 0.90
test_keepdims_outMethod · 0.90

Calls 2

_ureduceFunction · 0.90
getdataFunction · 0.85

Tested by 7

test_2dMethod · 0.72
test_2d_waxisMethod · 0.72
test_3dMethod · 0.72
test_neg_axisMethod · 0.72
test_out_1dMethod · 0.72
test_outMethod · 0.72
test_keepdims_outMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…