title: numpy recarray indexing based on intersection with external array
body: <p>I'm trying to subset the records in a numpy.recarray based on the common values between one of the recarrays fields and an external array.  For example,</p>
  
  <pre><code>a = np.array([(10, 'Bob', 145.7), (20, 'Sue', 112.3), (10, 'Jim', 130.5)],
          dtype=[('id', 'i4'), ('name', 'S10'), ('weight', 'f8')])
  a = a.view(np.recarray)
  
  b = np.array([10,30])
  </code></pre>
  
  <p>I want to take the intersection of a.id and b to determine what records to pull from the recarray, so that I get back:</p>
  
  <p>(10, 'Bob', 145.7)<br>
  (10, 'Jim', 130.5)</p>
  
  <p>Naively, I tried:</p>
  
  <pre><code>common = np.intersect1d(a.id, b)
  subset = a[common]
  </code></pre>
  
  <p>but of course that doesn't work because there is no a[10].  I also tried to do this by creating a reverse dict between the id field and the index and subsetted from there, e.g.</p>
  
  <pre><code>id_x_index = {}
  ids = a.id
  indexes = np.arange(a.size)
  for (id, index) in zip(ids, indexes):
      id_x_index[id] = index
  
  subset_indexes = np.sort([id_x_index[x] for x in ids if x in b])
  print a[subset_indexes]
  </code></pre>
  
  <p>but then I'm overriding dict values in id_x_index if a.id has duplicates, as in this case I get </p>
  
  <p>(10, 'Jim', 130.5)<br>
  (10, 'Jim', 130.5)</p>
  
  <p>I know I'm overlooking some simple way to get the appropriate indices into the recarray.  Thanks for help.</p>