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

Function median

numpy/lib/_function_base_impl.py:3915–4000  ·  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, sequence of int, None}, optional Axis or axes along which the m

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

Source from the content-addressed store, hash-verified

3913
3914@array_function_dispatch(_median_dispatcher)
3915def median(a, axis=None, out=None, overwrite_input=False, keepdims=False):
3916 """
3917 Compute the median along the specified axis.
3918
3919 Returns the median of the array elements.
3920
3921 Parameters
3922 ----------
3923 a : array_like
3924 Input array or object that can be converted to an array.
3925 axis : {int, sequence of int, None}, optional
3926 Axis or axes along which the medians are computed. The default,
3927 axis=None, will compute the median along a flattened version of
3928 the array. If a sequence of axes, the array is first flattened
3929 along the given axes, then the median is computed along the
3930 resulting flattened axis.
3931 out : ndarray, optional
3932 Alternative output array in which to place the result. It must
3933 have the same shape and buffer length as the expected output,
3934 but the type (of the output) will be cast if necessary.
3935 overwrite_input : bool, optional
3936 If True, then allow use of memory of input array `a` for
3937 calculations. The input array will be modified by the call to
3938 `median`. This will save memory when you do not need to preserve
3939 the contents of the input array. Treat the input as undefined,
3940 but it will probably be fully or partially sorted. Default is
3941 False. If `overwrite_input` is ``True`` and `a` is not already an
3942 `ndarray`, an error will be raised.
3943 keepdims : bool, optional
3944 If this is set to True, the axes which are reduced are left
3945 in the result as dimensions with size one. With this option,
3946 the result will broadcast correctly against the original `arr`.
3947
3948 Returns
3949 -------
3950 median : ndarray
3951 A new array holding the result. If the input contains integers
3952 or floats smaller than ``float64``, then the output data-type is
3953 ``np.float64``. Otherwise, the data-type of the output is the
3954 same as that of the input. If `out` is specified, that array is
3955 returned instead.
3956
3957 See Also
3958 --------
3959 mean, percentile
3960
3961 Notes
3962 -----
3963 Given a vector ``V`` of length ``N``, the median of ``V`` is the
3964 middle value of a sorted copy of ``V``, ``V_sorted`` - i
3965 e., ``V_sorted[(N-1)/2]``, when ``N`` is odd, and the average of the
3966 two middle values of ``V_sorted`` when ``N`` is even.
3967
3968 Examples
3969 --------
3970 >>> import numpy as np
3971 >>> a = np.array([[10, 7, 4], [3, 2, 1]])
3972 >>> a

Callers

nothing calls this directly

Calls 1

_ureduceFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…