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)
| 3844 | |
| 3845 | @array_function_dispatch(_median_dispatcher) |
| 3846 | def median(a, axis=None, out=None, overwrite_input=False, keepdims=False): |
| 3847 | """ |
| 3848 | Compute the median along the specified axis. |
| 3849 | |
| 3850 | Returns the median of the array elements. |
| 3851 | |
| 3852 | Parameters |
| 3853 | ---------- |
| 3854 | a : array_like |
| 3855 | Input array or object that can be converted to an array. |
| 3856 | axis : {int, sequence of int, None}, optional |
| 3857 | Axis or axes along which the medians are computed. The default |
| 3858 | is to compute the median along a flattened version of the array. |
| 3859 | A sequence of axes is supported since version 1.9.0. |
| 3860 | out : ndarray, optional |
| 3861 | Alternative output array in which to place the result. It must |
| 3862 | have the same shape and buffer length as the expected output, |
| 3863 | but the type (of the output) will be cast if necessary. |
| 3864 | overwrite_input : bool, optional |
| 3865 | If True, then allow use of memory of input array `a` for |
| 3866 | calculations. The input array will be modified by the call to |
| 3867 | `median`. This will save memory when you do not need to preserve |
| 3868 | the contents of the input array. Treat the input as undefined, |
| 3869 | but it will probably be fully or partially sorted. Default is |
| 3870 | False. If `overwrite_input` is ``True`` and `a` is not already an |
| 3871 | `ndarray`, an error will be raised. |
| 3872 | keepdims : bool, optional |
| 3873 | If this is set to True, the axes which are reduced are left |
| 3874 | in the result as dimensions with size one. With this option, |
| 3875 | the result will broadcast correctly against the original `arr`. |
| 3876 | |
| 3877 | .. versionadded:: 1.9.0 |
| 3878 | |
| 3879 | Returns |
| 3880 | ------- |
| 3881 | median : ndarray |
| 3882 | A new array holding the result. If the input contains integers |
| 3883 | or floats smaller than ``float64``, then the output data-type is |
| 3884 | ``np.float64``. Otherwise, the data-type of the output is the |
| 3885 | same as that of the input. If `out` is specified, that array is |
| 3886 | returned instead. |
| 3887 | |
| 3888 | See Also |
| 3889 | -------- |
| 3890 | mean, percentile |
| 3891 | |
| 3892 | Notes |
| 3893 | ----- |
| 3894 | Given a vector ``V`` of length ``N``, the median of ``V`` is the |
| 3895 | middle value of a sorted copy of ``V``, ``V_sorted`` - i |
| 3896 | e., ``V_sorted[(N-1)/2]``, when ``N`` is odd, and the average of the |
| 3897 | two middle values of ``V_sorted`` when ``N`` is even. |
| 3898 | |
| 3899 | Examples |
| 3900 | -------- |
| 3901 | >>> a = np.array([[10, 7, 4], [3, 2, 1]]) |
| 3902 | >>> a |
| 3903 | array([[10, 7, 4], |
nothing calls this directly
no test coverage detected