NumPy has np.percentile().
import numpy as np
a = np.array([1,2,3,4,5])
p = np.percentile(a, 50) # return 50th percentile, i.e. median.
>>> print(p)
3.0
SciPy has scipy.stats.scoreatpercentile(), in addition to many other statistical goodies.
NumPy
numpy.org โบ doc โบ stable โบ reference โบ generated โบ numpy.percentile.html
numpy.percentile โ NumPy v2.5 Manual
Compute the q-th percentile of the data along the specified axis.
NumPy
numpy.org โบ devdocs โบ reference โบ generated โบ numpy.percentile.html
numpy.percentile โ NumPy v2.6.dev0 Manual
Compute the q-th percentile of the data along the specified axis.
python numpy percentile
How do I calculate percentiles with python/numpy? #shorts
03:18
NumPy Percentile Tutorial: Master np.percentile() for Data Analysis ...
Simplify Percentile Calculation Using Numpy
11:24
Understanding Quantiles in Python: A Step-by-Step Guide (Numpy ...
11:08
DataFrame Percentile Quartiles using Numpy, Pandas, & Python - YouTube
NumPy
numpy.org โบ doc โบ 2.4 โบ reference โบ generated โบ numpy.percentile.html
numpy.percentile โ NumPy v2.4 Manual
Compute the q-th percentile of the data along the specified axis.
NumPy
numpy.org โบ doc โบ 2.1 โบ reference โบ generated โบ numpy.percentile.html
numpy.percentile โ NumPy v2.1 Manual
Compute the q-th percentile of the data along the specified axis.
Top answer 1 of 12
405
NumPy has np.percentile().
import numpy as np
a = np.array([1,2,3,4,5])
p = np.percentile(a, 50) # return 50th percentile, i.e. median.
>>> print(p)
3.0
SciPy has scipy.stats.scoreatpercentile(), in addition to many other statistical goodies.
2 of 12
95
By the way, there is a pure-Python implementation of percentile function, in case one doesn't want to depend on scipy. The function is copied below:
## {{{ http://code.activestate.com/recipes/511478/ (r1)
import math
import functools
def percentile(N, percent, key=lambda x:x):
"""
Find the percentile of a list of values.
@parameter N - is a list of values. Note N MUST BE already sorted.
@parameter percent - a float value from 0.0 to 1.0.
@parameter key - optional key function to compute value from each element of N.
@return - the percentile of the values
"""
if not N:
return None
k = (len(N)-1) * percent
f = math.floor(k)
c = math.ceil(k)
if f == c:
return key(N[int(k)])
d0 = key(N[int(f)]) * (c-k)
d1 = key(N[int(c)]) * (k-f)
return d0+d1
# median is 50th percentile.
median = functools.partial(percentile, percent=0.5)
## end of http://code.activestate.com/recipes/511478/ }}}
NumPy
numpy.org โบ doc โบ 2.0 โบ reference โบ generated โบ numpy.percentile.html
numpy.percentile โ NumPy v2.0 Manual
An array of weights associated with the values in a. Each value in a contributes to the percentile according to its associated weight. The weights array can either be 1-D (in which case its length must be the size of a along the given axis) or of the same shape as a.
NumPy
numpy.org โบ doc โบ 2.2 โบ reference โบ generated โบ numpy.percentile.html
numpy.percentile โ NumPy v2.2 Manual
Compute the q-th percentile of the data along the specified axis.
NumPy
numpy.org โบ doc โบ 1.20 โบ reference โบ generated โบ numpy.percentile.html
numpy.percentile โ NumPy v1.20 Manual
January 31, 2021 - Returns the q-th percentile(s) of the array elements.
NumPy
numpy.org โบ doc โบ 2.3 โบ reference โบ generated โบ numpy.percentile.html
numpy.percentile โ NumPy v2.3 Manual
Compute the q-th percentile of the data along the specified axis.
NumPy
numpy.org โบ doc โบ 1.25 โบ reference โบ generated โบ numpy.percentile.html
numpy.percentile โ NumPy v1.25 Manual
Given a vector V of length n, the q-th percentile of V is the value q/100 of the way from the minimum to the maximum in a sorted copy of V. The values and distances of the two nearest neighbors as well as the method parameter will determine the percentile if the normalized ranking does not ...
NumPy
numpy.org โบ doc โบ 1.26 โบ reference โบ generated โบ numpy.percentile.html
numpy.percentile โ NumPy v1.26 Manual
Given a vector V of length n, the q-th percentile of V is the value q/100 of the way from the minimum to the maximum in a sorted copy of V. The values and distances of the two nearest neighbors as well as the method parameter will determine the percentile if the normalized ranking does not ...
NumPy
numpy.org โบ doc โบ 1.23 โบ reference โบ generated โบ numpy.percentile.html
numpy.percentile โ NumPy v1.23 Manual
Returns the q-th percentile(s) of the array elements.
Programiz
programiz.com โบ python-programming โบ numpy โบ methods โบ percentile
NumPy percentile()
The percentile() method returns the q-th percentile(s) of the input array along the specified axis.
Codecademy
codecademy.com โบ docs โบ python:numpy โบ built-in functions โบ .percentile()
Python:NumPy | Built-in Functions | .percentile() | Codecademy
July 25, 2025 - The np.percentile() is a built-in method of Numpy, a statistical measure that indicates the value below which a given percentage of observations in a dataset falls.
NumPy
numpy.org โบ doc โบ 1.24 โบ reference โบ generated โบ numpy.percentile.html
numpy.percentile โ NumPy v1.24 Manual
Given a vector V of length n, the q-th percentile of V is the value q/100 of the way from the minimum to the maximum in a sorted copy of V. The values and distances of the two nearest neighbors as well as the method parameter will determine the percentile if the normalized ranking does not ...
NumPy
numpy.org โบ doc โบ 1.18 โบ reference โบ generated โบ numpy.percentile.html
numpy.percentile โ NumPy v1.18 Manual
Returns the q-th percentile(s) of the array elements.
SciPy
docs.scipy.org โบ doc โบ numpy-1.10.1 โบ reference โบ generated โบ numpy.percentile.html
numpy.percentile โ NumPy v1.10 Manual
Returns the qth percentile of the array elements.
NumPy
numpy.org โบ doc โบ 1.22 โบ reference โบ generated โบ numpy.percentile.html
numpy.percentile โ NumPy v1.22 Manual
Returns the q-th percentile(s) of the array elements.
SciPy
docs.scipy.org โบ doc โบ numpy-1.9.2 โบ reference โบ generated โบ numpy.percentile.html
numpy.percentile โ NumPy v1.9 Manual
Returns the qth percentile of the array elements.