Reputation: 10083
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
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