[Numpy-discussion] masked arrays as array indices

Ryan May rmay31 at gmail.com
Mon Sep 21 12:17:05 EDT 2009


2009/9/21 Ernest Adrogué <eadrogue at gmx.net>

> Hello there,
>
> Given a masked array such as this one:
>
> In [19]: x = np.ma.masked_equal([-1, -1, 0, -1, 2], -1)
>
> In [20]: x
> Out[20]:
> masked_array(data = [-- -- 0 -- 2],
>             mask = [ True  True False  True False],
>       fill_value = 999999)
>
> When you make an assignemnt in the vein of x[x == 0] = 25
> the result can be a bit puzzling:
>
> In [21]: x[x == 0] = 25
>
> In [22]: x
> Out[22]:
> masked_array(data = [25 25 25 25 2],
>             mask = [False False False False False],
>       fill_value = 999999)
>
> Is this the correct result or have I found a bug?
>

I see the same here on 1.4.0.dev7400.  Seems pretty odd to me.  Then again,
it's a bit more complex using masked boolean arrays for indexing since you
have True, False, and masked values.  Anyone have thoughts on what *should*
happen here?  Or is this it?

Ryan

-- 
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20090921/e701417e/attachment.html>


More information about the NumPy-Discussion mailing list