How to calculate percentile in Numpy?

Let’s see how to calculate percentile in Numpy Python module.
numpy percentile

Using Numpy percentile

To calculate percentile in Numpy use percentile function which Numpy is offering to you.

You can use below Python Numpy code:

import numpy as np

a = (1, 5, 7, 11, 87, 45)

print(f"{np.percentile(a, 10)}")
print(f"{np.percentile(a, 45)}")
print(f"{np.percentile(a, 50)}")
print(f"{np.percentile(a, 75)}")
print(f"{np.percentile(a, 95)}")

As you may notice there are two arguments of percentile function. The source of data and which percentile you may want to calculate in Python.

See also  Managing BufferError: Understanding Buffer Interface in NumPy

Check also how to calculate percentile in Excel.