title: numpy: multiply arbitrary shape array along first axis
body: <p>I want to multiply an array along it's first axis by some vector.</p>
  
  <p>For instance, if a is 2D, b is 1D, and a.shape[0] == b.shape[0], we can do:</p>
  
  <pre><code>a *= b[:, np.newaxis]
  </code></pre>
  
  <p>What if a has an arbitrary shape?  In numpy, the ellipsis "..." can be interpreted as "fill the remaining indices with ':'".  Is there an equivalent for filling the remaining axes with None/np.newaxis?</p>
  
  <p>The code below generates the desired result, but I would prefer a general vectorized way to accomplish this without falling back to a for loop.</p>
  
  <pre><code>from __future__ import print_function
  
  import numpy as np
  
  
  def foo(a, b):
      """
      Multiply a along its first axis by b
      """
      if len(a.shape) == 1:
          a *= b
      elif len(a.shape) == 2:
          a *= b[:, np.newaxis]
      elif len(a.shape) == 3:
          a *= b[:, np.newaxis, np.newaxis]
      else:
          n = a.shape[0]
          for i in range(n):
             a[i, ...] *= b[i]          
  
  n = 10
  b = np.arange(n)
  
  a = np.ones((n, 3))
  foo(a, b)
  print(a)
  
  a = np.ones((n, 3, 3))
  foo(a, b)
  print(a)
  </code></pre>