## Re: [Matplotlib-users] quantiles

 Re: [Matplotlib-users] quantiles From: John Hunter - 2003-08-26 15:04:51 ```>>>>> "Charles" == Charles Twardy writes: Charles> Hey all, I couldn't find any code to do quantiles in Charles> Python. It seems like it belongs in python-stats, and Charles> maybe other places like MLab or matplotlib. But at least Charles> 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): return x[int(p*Nx/100.0)] 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. JDH ```

 [Matplotlib-users] quantiles From: Charles Twardy - 2003-08-26 13:57:02 Attachments: quantile.py ```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. I've attached the code. It's based on the documentation given in R for help(quantile). It's pretty straightforward and works on the two testcases I've supplied. It doesn't handle missing values. At least, I have no reason to expect it would. -Charles -- Charles R. Twardy Monash University, School of CSSE ctwardy at alumni indiana edu +61(3) 9905 5823 (w) 5146 (fax) ~^~ "eloquence ought to be banish'd out of all civil Societies as a thing fatal to Peace and good Manners..." ~Sprat 1667 ```
 Re: [Matplotlib-users] quantiles From: John Hunter - 2003-08-26 15:04:51 ```>>>>> "Charles" == Charles Twardy writes: Charles> Hey all, I couldn't find any code to do quantiles in Charles> Python. It seems like it belongs in python-stats, and Charles> maybe other places like MLab or matplotlib. But at least Charles> 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): return x[int(p*Nx/100.0)] 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. JDH ```