This shouldn't work, but it does, because there are the same number of Trues in both indexing arrays. Do we really want this to happen?:
>>> a[row_idx, col_idx]
array([1, 6])
This shouldn't work, and it doesn't:
>>> col_idx = np.array([False, True, True, True])
>>> a[row_idx, col_idx]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: shape mismatch: objects cannot be broadcast to a single shape
It would be nice if something like this worked, or at least it should raise a different error, because those arrays **can** be broadcast to a single shape:
>>> a[row_idx[:, np.newaxis], col_idx]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: shape mismatch: objects cannot be broadcast to a single shape
For this there is the following workaround, although it does creation of a fully expanded boolean indexing array, which I was hoping the previous non-working code would avoid: