# [NumPy-Tickets] [NumPy] #1447: Inconsistent behavior when indexing a masked array with a bool array

NumPy Trac numpy-tickets@scipy....
Sun Apr 4 06:49:05 CDT 2010

```#1447: Inconsistent behavior when indexing a masked array with a bool array
---------------------------------------+------------------------------------
Reporter:  nathanielpeterson          |       Owner:  somebody
Type:  defect                     |      Status:  new
Priority:  normal                     |   Milestone:
Component:  Other                      |     Version:  1.3.0
Keywords:  bool-indexed masked array  |
---------------------------------------+------------------------------------
This part works as I would expected:

{{{
import numpy as np
a=np.ma.fix_invalid(np.array([np.nan,-1,0,1]))
b=np.ma.fix_invalid(np.array([np.nan,-1,0,1]))
idx=(a==b)
print(a[idx][3])
# 1.0
}}}

Note that a[idx] has shape (4,).
But if I change the first element of b from np.nan to 2.0 then
a[idx2] has shape (3,) despite np.alltrue(idx==idx2) being True:

{{{

c=np.ma.fix_invalid(np.array([2.0,-1,0,1]))
idx2=(a==c)
assert(np.alltrue(idx==idx2))
a[idx2][3]
}}}

{{{

# Traceback (most recent call last):
#   File "/home/np/test.py", line 12, in <module>
#     a[idx2][3]
#   File "/usr/lib/python2.6/dist-packages/numpy/ma/core.py", line 2578,
in __getitem__
#     dout = ndarray.__getitem__(ndarray.view(self, ndarray), indx)
# IndexError: index out of bounds
}}}

I looked at repr(idx) and repr(idx2) and they appear to have equal values
in all respects. Therefore, it seems inconsistent (and puzzling) why
a[idx2] does not behave the same as a[idx].

--
Ticket URL: <http://projects.scipy.org/numpy/ticket/1447>
NumPy <http://projects.scipy.org/numpy>
My example project
```

More information about the NumPy-Tickets mailing list