title: efficient processing of corresponding elements in two numpy arrays
body: <p>I have two arrays A and B of the same size. I'd need to get the values and indices of items in the arrays according to B's items. Here is my code:</p>
  
  <pre><code>promotes = [a for a,b in zip(A, B) if b == 1]
  demotes =  [a for a,b in zip(A, B) if b == 0]
  promotes_index = [k for k,(a,b) in enumerate(zip(A, B)) if b == 1]
  demotes_index =  [k for k,(a,b) in enumerate(zip(A, B)) if b == 0] 
  </code></pre>
  
  <p>I'm sure there is a more efficient way to compute promotes, demotes, and the indices. </p>
  
  <p>In more simple words, if A and promotes are like:</p>
  
  <pre><code>A = array([ 4,  6,  9, 10]))
  promotes = array([4, 9])
  </code></pre>
  
  <p>how could I get promote_index from A and promotes:</p>
  
  <pre><code>promotes_index = array([0, 2])
  </code></pre>
  
  <p>I appreciate any response.</p>