title: Indexing columns (or rows) in a numpy matrix with a Boolean list
body: <p>Given a numpy matrix <code>A</code> of shape <code>(m,n)</code> and a list <code>ind</code> of Boolean values with length <code>n</code>, I want to extract the columns of <code>A</code> where the corresponding element of the Boolean list is true.</p>
  
  <p>My first naive try</p>
  
  <pre><code>Asub = A[:,cols]
  </code></pre>
  
  <p>gives quite weird results, not necessary to cite here...</p>
  
  <p>Following pv.'s answer to <a href="https://stackoverflow.com/questions/7820809/understanding-weird-boolean-2d-array-indexing-behavior-in-numpy">this question</a>, I tried with <code>numpy.ix_</code> as follows:</p>
  
  <pre><code>&gt;&gt;&gt; A = numpy.diag([1,2,3])
  &gt;&gt;&gt; ind = [True, True, False]
  &gt;&gt;&gt; A[:,numpy.ix_(ind)]
  array([[[1, 0]],
  
         [[0, 2]],
  
         [[0, 0]]])
  &gt;&gt;&gt; A[:,numpy.ix_(ind)].shape
  (3, 1, 2)
  </code></pre>
  
  <p>Now the result is of inappropriate shape: I want to have a <code>(3,2)</code> resulting array. I guess I could collapse the result down to two dimensions, but there surely must be a better way of doing this?</p>