Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

percentile for masked array #4767

Open
tatarinova opened this Issue Jun 2, 2014 · 6 comments

Comments

Projects
None yet
7 participants

Hello,

I would like to know if it is possible to calculate a percentile when an input array is a masked array.

Natalia

Contributor

abalkin commented Jun 2, 2014

Take a look at ma.argsort.

Questions like this are better directed to the mailing list.

Contributor

juliantaylor commented Jun 2, 2014

there is currently no ma.percentile, but numpy 1.9 of which we will hopefully release a first beta this week, will contain np.nanpercentile which can be used to emulate ma.percentile

np.nanpercentile(maskedarray.filled(np.nan), (5, 95))

It would be great! Thanks for your response.

Jwely commented Dec 13, 2015

bump for adding a native ma.percentile function.

nguy commented Apr 6, 2016

Agreed, I currently use scipy.stats.mstats.mquantiles as an alternative.

gmonkman commented Aug 4, 2016 edited

Agree. nanpercentile under nanfunctions is welcome, but in keeping with the model of mask array support seen for numpy.mean and numpy.std for example, then we should have a masked array percentile to have numpy.percentile masked array aware (similiarly for other functions in the core library).

import numpy
a=numpy.array([numpy.nan,1,2,3,4,5,6,7,8,9])
print 'numpy.mean(numpy.ma.masked_invalid(a)): %f' % (numpy.mean(numpy.ma.masked_invalid(a)))
print 'numpy.mean(a): %f' % (numpy.mean(a))
print 'numpy.median(numpy.ma.masked_invalid(a)): %f' % (numpy.median(numpy.ma.masked_invalid(a)))
print 'numpy.percentile(numpy.ma.masked_invalid(a), [50]): %f' % (numpy.percentile(numpy.ma.masked_invalid(a), [50]))


[ nan   1.   2.   3.   4.   5.   6.   7.   8.   9.]
numpy.mean(numpy.ma.masked_invalid(a)): 5.000000
numpy.mean(a): nan
numpy.median(numpy.ma.masked_invalid(a)): nan
numpy.percentile(numpy.ma.masked_invalid(a), [50]): nan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment