[Numpy-discussion] masked index surprise
John Hunter
jdh2358 at gmail.com
Fri Aug 14 14:05:47 EDT 2009
I just tracked down a subtle bug in my code, which is equivalent to
In [64]: x, y = np.random.rand(2, n)
In [65]: z = np.zeros_like(x)
In [66]: mask = x>0.5
In [67]: z[mask] = x/y
I meant to write
z[mask] = x[mask]/y[mask]
so I can fix my code, but why is line 67 allowed
In [68]: z[mask].shape
Out[68]: (54,)
In [69]: (x/y).shape
Out[69]: (100,)
it seems like broadcasting would fail
In [70]: np.__version__
Out[70]: '1.4.0.dev7153'
In [71]:
More information about the NumPy-Discussion
mailing list