Skip to content
LearnPY
NumPyfunction reference

np.percentile

Compute a percentile of the values in an array.

Signature

np.percentile(a, q, axis=None)

What it does

np.percentile summarizes a distribution at a chosen rank. It is useful for robust feature ranges, clipping thresholds, and reading the spread of residuals without assuming a normal distribution.

Parameters

aarray_like
Values to summarize.
qfloat or array_like
Percentile or percentiles between zero and one hundred.
axisint, optionaloptional
Axis to reduce; default flattens the input.

Returns

ndarray or scalar

Example

pythonnp.percentile example
import numpy as np

latency = np.array([12, 15, 18, 21, 240])
print(np.percentile(latency, [50, 95]))

Output

[18. 240.]

Watch out for

  • The default linear interpolation can return a value that was never observed.
  • Percentiles are not additive across groups; recompute after combining data.