title: Using numpy.where() to return the indexes of a full array where the tested condition is on a sliced one
body: <p>I have the following 3 x 3 x 3 numpy array called <code>a</code> (the comments will make sense after you read the rest of the question):</p>
  
  <pre><code>array([[[8, 1, 0],     # irrelevant 1 (is at position 1 rather than 0)
          [1, 7, 5],     # the 1 on this line is what I am after!
          [1, 4, 9]],    # irrelevant 1 (out of the "cross")
  
         [[4, 0, 1],     # irrelevant 1 (is at position 2 rather than 0)
          [1, 0, 1],     # I'm only after the first 1 on this line!
          [6, 2, 1]],    # irrelevant 1 (is at position 2 rather than 0)
  
         [[0, 2, 2],
          [0, 6, 7],
          [3, 4, 9]]])
  </code></pre>
  
  <p>furthermore I have this list of indexes that refers to the "central cross" of said matrix, called <code>idx</code></p>
  
  <pre><code>[array([0, 1, 1, 1, 2]), array([1, 0, 1, 2, 1])]
  </code></pre>
  
  <p>EDIT: I call it "cross" as it marks the central column and row in the following:</p>
  
  <pre><code>&gt;&gt;&gt; a[..., 0]
  array([[8, 1, 1],
         [4, 1, 6],
         [0, 0, 3]])
  </code></pre>
  
  <p>What I would like to obtain is <strong>the indexes of all those arrays located at <code>idx</code> whose first value is 1</strong>, but I'm struggling in understanding how to use <code>numpy.where()</code> in the right way. Since...</p>
  
  <pre><code>&gt;&gt;&gt; a[..., 0][idx]
  array([1, 4, 1, 6, 0])
  </code></pre>
  
  <p>...I tried...</p>
  
  <pre><code>&gt;&gt;&gt; np.where(a[..., 0][idx] == 1)
  (array([0, 2]),)
  </code></pre>
  
  <p>...but as you can see it returns the index of the sliced array, not of <code>a</code>, while I would like to get:</p>
  
  <pre><code>[array([0, 1]), array([1, 1])]  #as a[0, 1, 0] and a [1, 1, 0] are equal to 1.
  </code></pre>
  
  <p>Thank you in advance for your help!</p>
  
  <p>PS: In the comments I have been suggested to try to give a broader scenario of applicability. Although it is not what I am using for, I suppose this could be used to process images as many 2D libraries do, with a source layer, a destination layer and a mask (see for example <a href="http://www.tortall.net/mu/wiki/CairoTutorial" rel="nofollow">cairo</a>). In this case the mask would be the <code>idx</code> array, and one might imagine working with the R channel of RGB colors (<code>a[..., 0]</code>).</p>