Hey all, I couldn't find any code to do quantiles in
> Python. It seems like it belongs in python-stats, and
> maybe other places like MLab or matplotlib. But at least
> in python-stats. Put it there if you think it belongs.
Good point. I'm going to follow the matlab signature for matplotlib.
The matlab function for this is 'prctile', and takes percents rather
than fractions for the percentile. Also it doesn't do interpolation.
def prctile(x, p = (0.0, 25.0, 50.0, 75.0, 100.0)):
Return the percentiles of x. p can either be a sequence of
percentil values or a scalar. If p is a sequence the i-th element
of the return sequence is the p(i)-th percentile of x
x = sort(x)
Nx = len(x)
if not iterable(p):
p = multiply(array(p), Nx/100.0)
ind = p.astype(Int)
ind = where(ind>=Nx, Nx-1, ind)
return take(x, ind)
I'll put it in matplotlib.mlab; let me know if you find any problems.