title: how to apply a mask from one array to another array?
body: <p>I've read the masked array documentation several times now, searched everywhere and feel thoroughly stupid. I can't figure out for the life in me how to apply a mask from one array to another. </p>
  
  <p>Example:</p>
  
  <pre><code>import numpy as np
  
  y = np.array([2,1,5,2])          # y axis
  x = np.array([1,2,3,4])          # x axis
  m = np.ma.masked_where(y&gt;2, y)   # filter out values larger than 5
  print m
  [2 1 -- 2]
  print np.ma.compressed(m)
  [2 1 2]
  </code></pre>
  
  <p>So this works fine.... but to plot this y axis, I need a matching x axis. How do I apply the mask from the y array to the x array? Something like this would make sense, but produces rubbish:</p>
  
  <pre><code>new_x = x[m.mask].copy()
  new_x
  array([5])
  </code></pre>
  
  <p>So, how on earth is that done (note the new x array needs to be a new array).</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>Well, it seems one way to do this works like this:</p>
  
  <pre><code>&gt;&gt;&gt; import numpy as np
  &gt;&gt;&gt; x = np.array([1,2,3,4])
  &gt;&gt;&gt; y = np.array([2,1,5,2])
  &gt;&gt;&gt; m = np.ma.masked_where(y&gt;2, y)
  &gt;&gt;&gt; new_x = np.ma.masked_array(x, m.mask)
  &gt;&gt;&gt; print np.ma.compressed(new_x)
  [1 2 4]
  </code></pre>
  
  <p>But that's incredibly messy! I'm trying to find a solution as elegant as IDL...</p>