title: Efficiently find row intersections of two 2-D numpy arrays
body: <p>I am trying to figure out an efficient way of finding row intersections of two <code>np.arrays</code>.</p>
  
  <p>Two arrays have the same shapes, and duplicate values in each row cannot happen.</p>
  
  <p>For example:</p>
  
  <pre><code>import numpy as np
  
  a = np.array([[2,5,6],
                [8,2,3],
                [4,1,5],
                [1,7,9]])
  
  b = np.array([[2,3,4],  # one element(2) in common with a[0] -&gt; 1
                [7,4,3],  # one element(3) in common with a[1] -&gt; 1
                [5,4,1],  # three elements(5,4,1) in common with a[2] -&gt; 3
                [7,6,9]]) # two element(9,7) in common with a[3] -&gt; 2
  </code></pre>
  
  <p>My desired output is : <code>np.array([1,1,3,2])</code></p>
  
  <p>It is easy to do this with a loop:</p>
  
  <pre><code>def get_intersect1ds(a, b):
      result = np.empty(a.shape[0], dtype=np.int)
      for i in xrange(a.shape[0]):
          result[i] = (len(np.intersect1d(a[i], b[i])))
      return result
  </code></pre>
  
  <p>Result:</p>
  
  <pre><code>&gt;&gt;&gt; get_intersect1ds(a, b)
  array([1, 1, 3, 2])
  </code></pre>
  
  <p>But is there a more efficient way to do it?</p>