[Numpy-discussion] Possible bug in indexed masked arrays
Nathaniel Peterson
nathanielpeterson08 at gmail.com
Fri Apr 2 01:08:49 EDT 2010
Is this behavior of masked arrays intended, or is it a bug?
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.
If that is true, why should a[idx] be different than a[idx2]?
More information about the NumPy-Discussion
mailing list