[Numpy-discussion] MA bug or feature?

Michael Sorich michael.sorich at gmail.com
Thu Jun 22 18:41:27 CDT 2006


On 6/23/06, Pierre GM <pgmdevlist at mailcan.com> wrote:
> On Wednesday 21 June 2006 22:01, Michael Sorich wrote:
> > Nevertheless, the differences between a masked array with a boolean
> > mask and a mask of booleans have caused me trouble before. Especially
> > when there are hidden in-place conversions of a mask which is a array
> > of False to a mask which is False. e.g.
>
> OK, I'm still using 0.9.8 and I can't help you with this one. In that version,
> N.asarray transforms the MA into a ndarray, so you lose the mask.

No, the mask of ma1 is converted in place to False. ma1 remains a MaskedArray

import numpy
ma1 = numpy.ma.array(((1.,2,3),(4,5,6)), mask=((0,0,0),(0,0,0)))
print ma1.mask, type(ma1)
numpy.asarray(ma1)
print ma1.mask, type(ma1)

--output--
[[False False False]
 [False False False]] <class 'numpy.core.ma.MaskedArray'>
False <class 'numpy.core.ma.MaskedArray'>

> But I wonder: if none of your values are masked, the natural behavior would be
> to have `data.mask==nomask`, which speeds up things a bit. This gain of time
> is why I was suggesting that `mask` would be forced to `nomask` at the
> creation, if `mask.any()==False`.
>
> Could you give me some examples of cases where you need the mask to stay as an
> array of False ?
> If you need to access the mask as an array, you can always use
> MA.getmaskarray.

If it did not sometimes effect the behaviour of the masked array, I
would not be worried about automatic conversions between the two forms
of the mask. Is it agreed that there should not be any differences in
the behavior of the two forms of masked array e.g. with a mask of
[[False,False],[False,False]] vs False? It is frustrating to track
down exceptions when the array has one behavior, then there is a
implicit conversion of the mask which changes the behaviour of the
array.

Mike




More information about the Numpy-discussion mailing list