title: numpy broadcast from first dimension
body: <p>In NumPy, is there an <em>easy</em> way to broadcast two arrays of dimensions e.g. <code>(x,y)</code> and <code>(x,y,z)</code>? NumPy broadcasting typically matches dimensions from the last dimension, so usual broadcasting will not work (it would require the first array to have dimension <code>(y,z)</code>).</p>
  
  <p>Background: I'm working with images, some of which are RGB (shape <code>(h,w,3)</code>) and some of which are grayscale (shape <code>(h,w)</code>). I generate alpha masks of shape <code>(h,w)</code>, and I want to apply the mask to the image via <code>mask * im</code>. This doesn't work because of the above-mentioned problem, so I end up having to do e.g. </p>
  
  <pre><code>mask = mask.reshape(mask.shape + (1,) * (len(im.shape) - len(mask.shape)))
  </code></pre>
  
  <p>which is ugly. Other parts of the code do operations with vectors and matrices, which also run into the same issue: it fails trying to execute <code>m + v</code> where <code>m</code> has shape  <code>(x,y)</code> and <code>v</code> has shape <code>(x,)</code>. It's possible to use e.g. <code>atleast_3d</code>, but then I have to remember how many dimensions I actually wanted.</p>