Numpy multi-dimensional slicing with multiple boolean arrays
<p>I'm trying to use individual 1-dimensional boolean arrays to slice a multi-dimension array. For some reason, this code doesn't work:</p>

<pre><code>&gt;&gt;&gt; a = np.ones((100, 200, 300, 2))
&gt;&gt;&gt; a.shape
(100, 200, 300, 2)
&gt;&gt;&gt; m1 = np.asarray([True]*200)
&gt;&gt;&gt; m2 = np.asarray([True]*300)
&gt;&gt;&gt; m2[-1] = False
&gt;&gt;&gt; a[:,m1,m2,:]
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
IndexError: shape mismatch: indexing arrays could not be broadcast together with shapes (200,) (299,) 
&gt;&gt;&gt; m2 = np.asarray([True]*300) # try again with all 300 dimensions True
&gt;&gt;&gt; a[:,m1,m2,:]
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
IndexError: shape mismatch: indexing arrays could not be broadcast together with shapes (200,) (300,) 
</code></pre>

<p>But this works just fine:</p>

<pre><code>&gt;&gt;&gt; a = np.asarray([[[1, 2], [3, 4], [5, 6]], [[11, 12], [13, 14], [15, 16]]])
&gt;&gt;&gt; a.shape
(2, 3, 2)
&gt;&gt;&gt; m1 = np.asarray([True, False, True])
&gt;&gt;&gt; m2 = np.asarray([True, False])
&gt;&gt;&gt; a[:,m1,m2]
array([[ 1,  5],
       [11, 15]])
</code></pre>

<p>Any idea of what I might be doing wrong in the first example?</p>