[SciPy-User] equivalent of R quantile() function in scipy

Jonathan Helmus jjhelmus@gmail....
Tue Dec 4 10:20:16 CST 2012


Mathieu,

numpy.percentile can can accept a sequence of percentiles as the second 
parameter:

In [8]: probs = [10.0, 30.0, 50.0, 70.0, 90.0]

In [9]: a = np.arange(100)

In [10]: np.percentile(a, probs)
Out[10]:
[9.9000000000000004,
  29.699999999999999,
  49.5,
  69.299999999999997,
  89.100000000000009]


Or you could use a list comprehension with scipy.stat.scoreatpercentile:

In [11]: [scipy.stats.scoreatpercentile(a, i) for i in probs]
Out[11]:
[9.9000000000000004,
  29.699999999999999,
  49.5,
  69.299999999999997,
  89.100000000000009]


The first solution is probably faster as the sequence is only sorted 
once. Hope this helps,

     - Jonathan Helmus



On 12/04/2012 10:55 AM, servant mathieu wrote:
> Dear list,
> From an array X of values, the quantile () function in R can return 
> the score at any given specified quantile : e.g., quant_values = 
> quantile (X, probs = c(.1, .3, .5, .7, .9)).
> The scoreatpercentile() function in scipy seems to to the same stuff. 
> However, you can specify only one quantile per function call e.g.  
> quant_value = scoreatpercentile (X, per = 10) etc..
> Is it possible to return more than one quantile per function call?
> Cheers,
> Mathieu
>
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20121204/68eb6ba9/attachment.html 


More information about the SciPy-User mailing list