[Numpy-discussion] Re: New version of compress for you
Michael Haggerty
mhagger at alum.mit.edu
Fri May 11 13:59:14 EDT 2001
Paul F. Dubois writes:
> def compress (condition, x, dimension=-1):
> """Select those parts of x for which condition is true.
> Masked values in condition are considered false.
> """
> c = filled(condition, 0)
> m = getmask(x)
> if m is not None:
> m=Numeric.compress(c, m, dimension)
> d = Numeric.compress(c, filled(x), dimension)
> return masked_array(d, m)
>
>
> I did want a treatment of masked conditions. Consider:
>
> compress( x > 10, x)
I see your point, but this doesn't generalize to x having more than
one dimension. And with my semantics, for your example (assuming
1-d), you could substitute
compress((x > 10).filled(0), x)
which isn't very obscure. Moreover, sometimes it is interesting to
compress an array in such a way that masked values are carried along
as masked values; this cannot be done with the existing compress().
Michael
--
Michael Haggerty
mhagger at alum.mit.edu
More information about the NumPy-Discussion
mailing list