user1821176
user1821176

Reputation: 1191

A parameter is missing for correct numpy percentiles?

I'm using numpy to calculate percentiles for an array. I found that numpy gives me the right answer for the 50th percentile but not for the 25th or 75th (correct answers 12 and 19.5 respectively). Is there some parameter I'm missing to note?

import numpy as np

c = [10, 14, 16, 19, 20]     

print(np.percentile(c, 25))

print(np.percentile(c, 50))

print(np.percentile(c, 75))

Upvotes: 0

Views: 50

Answers (1)

Pinyi Wang
Pinyi Wang

Reputation: 862

The 25th and 75th percentile of [10, 14, 16, 19, 20] are 14 and 19, so it's returning the right answer.

In case you want to specify the interpolation method to use when the desired percentile lies between two data points, you can check out the interpolation arguments in the documentation.

Hope this helps!

Upvotes: 1

Related Questions