title: Return common element indices between two numpy arrays
body: <p>I have two arrays, a1 and a2. Assume <code>len(a2) &gt;&gt; len(a1)</code>, and that a1 is a subset of a2. </p>
  
  <p>I would like a quick way to return the a2 indices of all elements in a1. The time-intensive way to do this is obviously:</p>
  
  <pre><code>from operator import indexOf
  indices = []
  for i in a1:
      indices.append(indexOf(a2,i))
  </code></pre>
  
  <p>This of course takes a long time where a2 is large. I could also use numpy.where() instead (although each entry in a1 will appear just once in a2), but I'm not convinced it will be quicker. I could also traverse the large array just once:</p>
  
  <pre><code>for i in xrange(len(a2)):
      if a2[i] in a1:
          indices.append(i)
  </code></pre>
  
  <p>But I'm sure there is a faster, more 'numpy' way - I've looked through the numpy method list, but cannot find anything appropriate.</p>
  
  <p>Many thanks in advance,</p>
  
  <p>D</p>