title: NumPy: counting sizes of row-wise intersections between two arrays
body: <p>I have 2 arrays filled by integers lower than 100. A number can't appear twice in a row.</p>
  
  <ul>
  <li>Array1: nrow=100 000 ; ncol=5 </li>
  <li>Array2: nrow=50 000  ; ncol=5 </li>
  </ul>
  
  <p>I'd like to create a 3rd array <em>(Intersection)</em> with the number of similar element between each row of Array1 and each row of Array2.</p>
  
  <pre><code>def Intersection(array1, array2):
      Intersection = np.empty([ array1.shape[0]  , array2.shape[0] ], dtype=int8)
      for i in range(0, array1.shape[0]):
          for j in range(0, array2.shape[0]):
              Intersection[i,j] = len( set(array1[i,]).intersection(array2[j,]) )
      return Intersection
  </code></pre>
  
  <p>Here is an example:</p>
  
  <pre><code>array1 = np.array([[1, 2, 3, 4, 5], [2, 3, 4, 5, 6], [7,8,9,10,11] ])
  array2 = np.array([[1, 3, 7, 20, 21], [1, 43, 104, 115, 116], [6,30,91,110,121] ])
  #Expected result:
  array([[2, 1, 0],
         [1, 0, 1],
         [1, 0, 0]], dtype=int8)
  </code></pre>
  
  <p>This naive solution with nested loops is very slow. <strong>How could I vectorize it ?</strong></p>