title: Fast vectorized indexing in numpy
body: <p>Suppose we have an array of indices of another numpy array:</p>
  
  <pre><code>import numpy as np
  a = np.array([0, 3, 1])
  b = np.array([0, 10, 20, 30, 40, 50, 60, 70])
  </code></pre>
  
  <p>We can use the array <code>a</code> as index directly:</p>
  
  <pre><code>b[a] # np.array([0, 30, 10])
  </code></pre>
  
  <p>But what if array a has more than one dimension? For example,</p>
  
  <pre><code>a = np.array([[0, 2], [1, 3], [2, 4]])
  # I want to get b[a] = np.array([[0, 20], [10, 30], [20, 40]])
  </code></pre>
  
  <p>Numpy indexing doesn't work if the number of dimensions of a is greater than 1. We can achieve the desired result by using <code>map</code></p>
  
  <pre><code>map(lambda x: b[x], a)
  </code></pre>
  
  <p>However, it is quite slow.  For 1-dimensional case, direct indexing is about 10-100 times faster than using <code>map</code>. </p>
  
  <p>Is there a way to do it faster?</p>