title: Extending numpy mask
body: <p>I want to mask a numpy array <code>a</code> with <code>mask</code>. The mask doesn't have exactly the same shape as <code>a</code>, but it is possible to mask <code>a</code> anyway (I guess because of the additional dimension being 1-dimensional (broadcasting?)).</p>
  
  <pre><code>a.shape
  &gt;&gt;&gt; (3, 9, 31, 2, 1)
  mask.shape
  &gt;&gt;&gt; (3, 9, 31, 2)
  masked_a = ma.masked_array(a, mask)
  </code></pre>
  
  <p>The same logic however, does not apply to array <code>b</code> which has 5 elements in its last dimension.</p>
  
  <pre><code>ext_mask = mask[..., np.newaxis] # extending or not extending has same effect
  ext_mask.shape
  &gt;&gt;&gt; (3, 9, 31, 2, 1)
  
  b.shape
  &gt;&gt;&gt; (3, 9, 31, 2, 5)
  masked_b = ma.masked_array(b, ext_mask)
  &gt;&gt;&gt; numpy.ma.core.MaskError: Mask and data not compatible: data size is 8370, mask size is 1674.
  </code></pre>
  
  <p>How can I create a <code>(3, 9, 31, 2, 5)</code> mask from a <code>(3, 9, 31, 2)</code> mask by expanding any <code>True</code> value in the last dimension of the <code>(3, 9, 31, 2)</code> mask to <code>[True, True, True, True, True]</code> (and <code>False</code> respectively)?</p>