numpy.median(arr, axis = None) : Compute the median of the given data (array elements) along the specified axis.
How to calculate median?
- Given data points.
- Arrange them in ascending order
- Median = middle term if total no. of terms are odd.
- Median = Average of the terms in the middle (if total no. of terms are even)
arr : [array_like]input array.
axis : [int or tuples of int]axis along which we want to calculate the median. Otherwise, it will consider arr to be flattened(works on all the axis). axis = 0 means along the column and axis = 1 means working along the row.
out : [ndarray, optional] Different array in which we want to place the result. The array must have the same dimensions as expected output.
dtype : [data-type, optional]Type we desire while computing median.
Results : Median of the array (a scalar value if axis is none) or array with median values along specified axis.
arr : [20, 2, 7, 1, 34] median of arr : 7.0
median of arr, axis = None : 15.0 median of arr, axis = 0 : [15. 6. 27. 8. 19.] median of arr, axis = 1 : [17. 15. 4.] out_arr : [0 1 2] median of arr, axis = 1 : [17 15 4]
- Important differences between Python 2.x and Python 3.x with examples
- Python | Set 4 (Dictionary, Keywords in Python)
- Python | Sort Python Dictionaries by Key or Value
- set add() in python
- try and except in Python
- chr() in Python
- Python | a += b is not always a = a + b
- max() and min() in Python
- SQL using Python | Set 1
- abs() in Python
- Any & All in Python
- zip() in Python
- bin() in Python
- pow() in Python
- Python Set | pop()
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.