title: Deleting masked elements in numpy array
body: <p>I have some arrays that contain masked elements (from <code>Numpy.MaskedArray</code>), e.g.</p>
  
  <pre><code>data = [0,1,masked,3,masked,5,...]
  </code></pre>
  
  <p>Where the mask doesn't follow a regular pattern.</p>
  
  <p>I want to iterate through the array and simply delete all elements that are masked to end up with:</p>
  
  <pre><code>data = [0,1,3,5,...]
  </code></pre>
  
  <p>I've tried a loop like:</p>
  
  <pre><code>for i in xrange(len(data)):
      if np.ma.is_masked(data[i]):
          data.pop(i)
  </code></pre>
  
  <p>But I get the error: <code>local variable 'data' referenced before assignment</code></p>
  
  <p>Do I have to create a new array and add the unmasked elements? Or is there a <code>MaskedArray</code> function that can automatically do this? I've had a look at the documentation but it's not obvious to me.</p>
  
  <p>Thanks!</p>