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 › 2.2 › reference › generated › numpy.percentile.html
numpy.percentile — NumPy v2.2 Manual
numpy.percentile(a, q, axis=None, out=None, overwrite_input=False, method='linear', keepdims=False, *, weights=None, interpolation=None)[source]#
NumPy
numpy.org › doc › 2.0 › reference › generated › numpy.percentile.html
numpy.percentile — NumPy v2.0 Manual
If q is a single percentile and axis=None, then the result is a scalar. If multiple percentiles are given, first axis of the result corresponds to the percentiles. The other axes are the axes that remain after the reduction of a. If the input contains integers or floats smaller than float64, ...
Videos
03:18
NumPy Percentile Tutorial: Master np.percentile() for Data Analysis ...
11:08
DataFrame Percentile Quartiles using Numpy, Pandas, & Python - YouTube
Percentiles in Machine Learning | numpy.percentile( ) - YouTube
Simplify Percentile Calculation Using Numpy
03:09
How do I calculate percentiles with python/numpy? - YouTube
21:31
How to Calculate Percentiles in Python: np.percentile() - YouTube
NumPy
numpy.org › devdocs › reference › generated › numpy.percentile.html
numpy.percentile — NumPy v2.5.dev0 Manual
numpy.percentile(a, q, axis=None, out=None, overwrite_input=False, method='linear', keepdims=False, *, weights=None)[source]#
SciPy
docs.scipy.org › doc › numpy-1.9.2 › reference › generated › numpy.percentile.html
numpy.percentile — NumPy v1.9 Manual
numpy.percentile(a, q, axis=None, out=None, overwrite_input=False, interpolation='linear', keepdims=False)[source]¶ · Compute the qth percentile of the data along the specified axis. Returns the qth percentile of the array elements. See also · mean, median ·
NumPy
numpy.org › doc › stable › reference › generated › numpy.percentile.html
numpy.percentile — NumPy v2.4 Manual
numpy.percentile(a, q, axis=None, out=None, overwrite_input=False, method='linear', keepdims=False, *, weights=None)[source]#
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/ }}}
SciPy
docs.scipy.org › doc › numpy-1.10.1 › reference › generated › numpy.percentile.html
numpy.percentile — NumPy v1.10 Manual
numpy.percentile(a, q, axis=None, out=None, overwrite_input=False, interpolation='linear', keepdims=False)[source]¶ · Compute the qth percentile of the data along the specified axis. Returns the qth percentile of the array elements. See also · mean, median ·
NumPy
numpy.org › doc › 2.1 › reference › generated › numpy.percentile.html
numpy.percentile — NumPy v2.1 Manual
numpy.percentile(a, q, axis=None, out=None, overwrite_input=False, method='linear', keepdims=False, *, weights=None, interpolation=None)[source]#
SciPy
docs.scipy.org › doc › numpy-1.12.0 › reference › generated › numpy.percentile.html
numpy.percentile — NumPy v1.12 Manual
numpy.percentile(a, q, axis=None, out=None, overwrite_input=False, interpolation='linear', keepdims=False)[source]¶ · Compute the qth percentile of the data along the specified axis. Returns the qth percentile(s) of the array elements. See also · mean, median, nanpercentile ·
NumPy
numpy.org › doc › 2.2 › reference › generated › numpy.nanpercentile.html
numpy.nanpercentile — NumPy v2.2 Manual
numpy.nanpercentile(a, q, axis=None, out=None, overwrite_input=False, method='linear', keepdims=<no value>, *, weights=None, interpolation=None)[source]# Compute the qth percentile of the data along the specified axis, while ignoring nan values.
Jorisvandenbossche
jorisvandenbossche.github.io › numpy › reference › generated › numpy.percentile.html
numpy.percentile — NumPy v1.18.dev0 Manual
numpy.percentile(a, q, axis=None, out=None, overwrite_input=False, interpolation='linear', keepdims=False)[source]¶ · Compute the q-th percentile of the data along the specified axis. Returns the q-th percentile(s) of the array elements. Parameters · aarray_like ·
NumPy
numpy.org › doc › 1.20 › reference › generated › numpy.percentile.html
numpy.percentile — NumPy v1.20 Manual
January 31, 2021 - numpy.percentile(a, q, axis=None, out=None, overwrite_input=False, interpolation='linear', keepdims=False)[source]¶
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 ...
JAX Documentation
docs.jax.dev › en › latest › _autosummary › jax.numpy.percentile.html
jax.numpy.percentile — JAX documentation
jax.numpy.percentile(a, q, axis=None, out=None, overwrite_input=False, method='linear', keepdims=False)[source]#
SciPy
docs.scipy.org › doc › › numpy-1.8.0 › reference › generated › numpy.percentile.html
numpy.percentile — NumPy v1.8 Manual
numpy.percentile(a, q, axis=None, out=None, overwrite_input=False)[source]¶ · Compute the qth percentile of the data along the specified axis. Returns the qth percentile of the array elements. See also · mean, median · Notes · Given a vector V of length N, the qth percentile of V is the ...
Programiz
programiz.com › python-programming › numpy › methods › percentile
NumPy percentile()
Stop copy pasting code you don't actually understand ... Become a certified Python programmer. ENROLL ... Created with over a decade of experience. ... Created with over a decade of experience and thousands of feedback. ... Try Programiz PRO! ... Become a certified Python programmer. Try Programiz PRO! ... The percentile() method computes the q-th percentile of the data along the specified axis. import numpy as np # create an array array1 = np.array([0, 1, 2, 3, 4, 5, 6, 7])
TutorialsPoint
tutorialspoint.com › numpy › numpy_percentile_function.htm
NumPy percentile() Function
The percentile() function performs interpolation when the desired percentile lies between two data points in the array. By default, it uses linear interpolation to estimate the result. Following is the syntax of the NumPy percentile() function −
Codecademy
codecademy.com › docs › python:numpy › built-in functions › .percentile()
Python:NumPy | Built-in Functions | .percentile() | Codecademy
July 25, 2025 - NumPy’s .percentile() function computes the q-th percentile of data along a specified axis, making it an essential tool for statistical analysis and data exploration.