title: Extract indices of intersecting array from numpy 2D array in subarray
body: <p>I have two 2D numpy square arrays, A and B. B is an array extracted from A where a certain number of columns and rows (with the same indices) have been stripped. Both of them are symmetric. For instance, A and B could be:</p>
  
  <pre><code>A = np.array([[1,2,3,4,5],
                [2,7,8,9,10],
                [3,8,13,14,15],
                [4,9,14,19,20],
                [5,10,15,20,25]])
  B = np.array([[1,3,5],
                [3,13,15],
                [5,15,25]])
  </code></pre>
  
  <p>such that the missing indices are [1,3] and intersecting indices are [0,2,4].</p>
  
  <p>Is there a "smart" way to extract the indices in A corresponding to the rows/columns present in B that involves advanced indexing and such? All I could come up with was:</p>
  
  <pre><code>        import numpy as np
          index = np.array([],dtype=int)
          n,m = len(A),len(B)
          for j in range(n):
              k = 0
              while set(np.intersect1d(B[j],A[k])) != set(B[j]) and k&lt;m:
                  k+=1
              np.append(index,k)
  </code></pre>
  
  <p>which I'm aware is slow and resource-consuming when dealing with large arrays.</p>
  
  <p>Thank you!</p>
  
  <p><strong>Edit:</strong>
  I did find a smarter way. I extract the diagonal from both arrays and perform the aforementioned loop on it with a simple equality check:</p>
  
  <pre><code>        index = []
          a = np.diag(A)
          b = np.diag(B)
          for j in range(len(b)):
              k = 0
              while a[j+k] != b[j] and k&lt;n:
                  k+=1
              index.append(k+j)
  </code></pre>
  
  <p>Although it still doesn't use advanced indexing and still iterates over a potentially long list, this partial solution looks cleaner and I'm going to stick with it for the time being.</p>