title: How to get 2d array of indices from 1d array?
body: <p>I'm looking for an efficient way to return indices for a 2d array based on values in a 1d array. I currently have a nested for loop set up that is painfully slow.</p>
  
  <p>Here is some example data and what I want to get:</p>
  
  <pre><code>data2d = np.array( [  [1,2] , [1,3] ,[3,4], [1,2] , [7,9] ])
  
  data1d = np.array([1,2,3,4,5,6,7,8,9])
  </code></pre>
  
  <p>I would like to return the indices where data2d is equal to data1d. My desired output would be this 2d array:</p>
  
  <pre><code>locs = np.array([[0, 1], [0, 2], [2, 3], [0, 1], [6, 8]])
  </code></pre>
  
  <p>The only thing I've come up with is the nested for loop:</p>
  
  <pre><code>locs = np.full((np.shape(data2d)), np.nan)
  
  for i in range(0, 5):
      for j in range(0, 2):
          loc_val = np.where(data1d == data2d[i, j])
          loc_val = loc_val[0]
          locs[i, j] = loc_val
  </code></pre>
  
  <p>This would be fine for a small set of data but I have 87,600 2d grids that are each 428x614 grid points.</p>