kilojoules
kilojoules

Reputation: 10083

Why doesn't numpy's 50th percentile return the mean?

I have found that numpy's 50th percentile doesn't return a perfect mean. Why is this? By definiiton, the 50th percentile should be the mean.

In [1]: s = [1.3424,4.221124,5.11,2.4432]

In [2]: sum(s)/len(s)
Out[2]: 3.2791810000000003

In [3]: np.percentile(s,50)
Out[3]: 3.3321619999999998

In [15]: s = [1.3424,4.221124,5.11,2.4432]
In [4]: sum(s)/len(s)
Out[4]: 3.2791810000000003

In [5]: np.percentile(s,50)
Out[5]: 3.3321619999999998

Upvotes: 1

Views: 302

Answers (1)

Dan D.
Dan D.

Reputation: 74655

The documentation states that at q=50 it returns not the mean but the median:

This function is the same as the median if q=50, the same as the minimum if q=0 and the same as the maximum if q=100.

See http://docs.scipy.org/doc/numpy-dev/reference/generated/numpy.percentile.html

Upvotes: 3

Related Questions