Python 3.4 has statistics.median:

Return the median (middle value) of numeric data.

When the number of data points is odd, return the middle data point. When the number of data points is even, the median is interpolated by taking the average of the two middle values:

>>> median([1, 3, 5])
3
>>> median([1, 3, 5, 7])
4.0

Usage:

import statistics

items = [6, 1, 8, 2, 3]

statistics.median(items)
#>>> 3

It's pretty careful with types, too:

statistics.median(map(float, items))
#>>> 3.0

from decimal import Decimal
statistics.median(map(Decimal, items))
#>>> Decimal('3')
Answer from Veedrac on Stack Overflow
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.median.html
numpy.median — NumPy v2.4 Manual
If out is specified, that array is returned instead. ... Given a vector V of length N, the median of V is the middle value of a sorted copy of V, V_sorted - i e., V_sorted[(N-1)/2], when N is odd, and the average of the two middle values of V_sorted when N is even.
🌐
Machine Learning Plus
machinelearningplus.com › blog › numpy.median() – how to compute median in python
numpy.median() - How to compute median in Python - | MLPlus
January 31, 2023 - numpy.median function is used to calculate the median of an array along a specific axis or multiple axes
🌐
NumPy
numpy.org › devdocs › reference › generated › numpy.median.html
numpy.median — NumPy v2.5.dev0 Manual
If out is specified, that array is returned instead. ... Given a vector V of length N, the median of V is the middle value of a sorted copy of V, V_sorted - i e., V_sorted[(N-1)/2], when N is odd, and the average of the two middle values of V_sorted when N is even.
🌐
GeeksforGeeks
geeksforgeeks.org › python › find-median-of-list-in-python
Find Median of List in Python - GeeksforGeeks
July 12, 2025 - Sorts the list in ascending order, then finds the middle value based on list length to calculate the median. It's a simple and direct way to find the median.
🌐
Vultr Docs
docs.vultr.com › python › third-party › numpy › median
Python Numpy median() - Calculate Median Value | Vultr Docs
November 15, 2024 - Create an array of numbers. Use numpy.median() to calculate the median.
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › how to use median() in numpy?
How to Use median() in NumPy? - Spark By {Examples}
March 27, 2024 - The numpy.median() function is used to calculate the median of single-dimensional as well as multi-dimensional arrays. In this article, I will explain how to use the NumPy median() function in Python to return the median of the array elements.
Find elsewhere
🌐
NumPy
numpy.org › doc › 2.3 › reference › generated › numpy.median.html
numpy.median — NumPy v2.3 Manual
If out is specified, that array is returned instead. ... Given a vector V of length N, the median of V is the middle value of a sorted copy of V, V_sorted - i e., V_sorted[(N-1)/2], when N is odd, and the average of the two middle values of V_sorted when N is even.
🌐
GeeksforGeeks
geeksforgeeks.org › numpy-median-in-python
numpy.median() in Python - GeeksforGeeks
November 28, 2018 - numpy.median(arr, axis = None) : Compute the median of the given data (array elements) along the specified axis.
🌐
Sharp Sight
sharpsight.ai › blog › numpy-median
How to use the NumPy median function - Sharp Sight
February 6, 2024 - The NumPy median function computes the median of the values in a NumPy array. Note that the NumPy median function will also operate on “array-like objects” like Python lists.
🌐
W3Schools
w3schools.com › python › ref_stat_median.asp
Python statistics.median() Method
Tip: The mathematical formula for Median is: Median = {(n + 1) / 2}th value, where n is the number of values in a set of data. In order to calculate the median, the data must first be sorted in ascending order.
🌐
NumPy
numpy.org › doc › 2.0 › reference › generated › numpy.median.html
numpy.median — NumPy v2.0 Manual
If out is specified, that array is returned instead. ... Given a vector V of length N, the median of V is the middle value of a sorted copy of V, V_sorted - i e., V_sorted[(N-1)/2], when N is odd, and the average of the two middle values of V_sorted when N is even.
🌐
NumPy
numpy.org › doc › 2.2 › reference › generated › numpy.ma.median.html
numpy.ma.median — NumPy v2.2 Manual
A new array holding the result ... input data-type, otherwise. ... 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....
🌐
Data Science Parichay
datascienceparichay.com › home › blog › get the median of numpy array – (with examples)
Get the Median of Numpy Array - (With Examples) - Data Science Parichay
June 22, 2022 - You can use the Numpy median() function to get the median value of a Numpy array. Pass the array as an argument.