title: faster alternative to numpy.where?
body: <p>I have a 3d array filled with integers from 0 to N. I need a list of the indices corresponding to where the array is equal 1, 2, 3, ... N. I can do it with np.where as follows:</p>
  
  <pre><code>N = 300
  shape = (1000,1000,10)
  data = np.random.randint(0,N+1,shape)
  indx = [np.where(data == i_id) for i_id in range(1,data.max()+1)]
  </code></pre>
  
  <p>but this is quite slow. According to this question
  <a href="https://stackoverflow.com/questions/18452591/fast-python-numpy-where-functionality">fast python numpy where functionality?</a>
  it should be possible to speed up the index search quite a lot, but I haven't been able to transfer the methods proposed there to my problem of getting the actual indices. What would be the best way to speed up the above code?</p>
  
  <p>As an add-on: I want to store the indices later, for which it makes sense to use np.ravel_multi_index to reduce the size from saving 3 indices to only 1, i.e. using:</p>
  
  <pre><code>indx = [np.ravel_multi_index(np.where(data == i_id), data.shape) for i_id in range(1, data.max()+1)]
  </code></pre>
  
  <p>which is closer to e.g. Matlab's find function. Can this be directly incorporated in a solution that doesn't use np.where?</p>