title: How to invert numpy.where (np.where) function
body: <p>I frequently use the numpy.where function to gather a tuple of indices of a matrix having some property.  For example</p>
  
  <pre><code>import numpy as np
  X = np.random.rand(3,3)
  &gt;&gt;&gt; X
  array([[ 0.51035326,  0.41536004,  0.37821622],
     [ 0.32285063,  0.29847402,  0.82969935],
     [ 0.74340225,  0.51553363,  0.22528989]])
  &gt;&gt;&gt; ix = np.where(X &gt; 0.5)
  &gt;&gt;&gt; ix
  (array([0, 1, 2, 2]), array([0, 2, 0, 1]))
  </code></pre>
  
  <p>ix is now a tuple of ndarray objects that contain the row and column indices, whereas the sub-expression X>0.5 contains a single boolean matrix indicating which cells had the >0.5 property.  Each representation has its own advantages.</p>
  
  <p>What is the best way to take ix object and convert it back to the boolean form later when it is desired?   For example</p>
  
  <pre><code>G = np.zeros(X.shape,dtype=np.bool)
  &gt;&gt;&gt; G[ix] = True
  </code></pre>
  
  <p>Is there a one-liner that accomplishes the same thing?</p>