title: Numpy: index array by array
body: <pre><code>&gt;&gt;&gt; idx = np.random.randint(2, size=(9, 31))
  &gt;&gt;&gt; a = np.random.random((9, 31, 2))
  &gt;&gt;&gt; a[idx].shape
  (9, 31, 31, 2)
  </code></pre>
  
  <p>Why is the above not resulting in at least a shape of <code>(9, 31, 1)</code>, or even better <code>(9, 31)</code>? How can I get it to return a selection based on the values in <code>idx</code>?</p>
  
  <p><strong>Update</strong></p>
  
  <p>This is perhaps a more concrete and hopefully analogue example: Assume this array</p>
  
  <pre><code>a = np.asarray([[1, 2], [3, 4], [5, 6], [7, 8]])
  </code></pre>
  
  <p>How would I go about selection the array <code>[1, 4, 5, 8]</code> (i.e. the 0th, 1st, 0th, 1st element of each row)?</p>