SourceForge logo
SourceForge logo
Menu

matplotlib-users

From: Charles T. <ct...@ma...> - 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
From: John H. <jdh...@ac...> - 2003年08月26日 15:04:51
>>>>> "Charles" == Charles Twardy <ct...@ma...> 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
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /