VOOZH about

URL: https://www.geeksforgeeks.org/python/numpy-percentile-in-python/

⇱ numpy.percentile() in python - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

numpy.percentile() in python

Last Updated : 21 Jun, 2025

numpy.percentile() compute the q-th percentile of data along the specified axis. A percentile is a measure indicating the value below which a given percentage of observations in a group falls. Example:


Output
5.0

Syntax

numpy.percentile(a, q, axis=None, out=None, overwrite_input=False, interpolation='linear', keepdims=False, method='linear')

Parameters:

Parameter

Description

a

Input array or object that can be converted to an array

q

Percentile(s) to compute (0–100). Can be scalar or array-like

axis

Axis along which the percentiles are computed. Default is None (flattened)

out

Optional output array

overwrite_input

If True, the input array can be modified for memory efficiency

interpolation

(Deprecated) Use method instead

method

Method to compute percentile: 'linear', 'lower', 'higher', 'midpoint', 'nearest'

keepdims

If True, the reduced axes are left in the result as dimensions with size one

Returns: The q-th percentile(s) of the array elements. If q is a list, it returns multiple percentiles.

Examples

Example 1: In this example, we compute the 25th, 50th and 75th percentiles of a 1D array.


Output
[20. 30. 40.]

Example 2: In this example, we compute the 50th percentile (median) along each row of a 2D array using the axis parameter.


Output
[7. 2.]

Example 3: In this example, we compute the 50th percentile (median) using the method='lower' option.


Output
2

Example 4: In this example, we compute the 50th percentile (median) along each row of a 2D array and use keepdims=True to preserve the original dimensions.


Output
[[20.]
 [50.]]
Comment