title: multiply numpy ndarray with 1d array along a given axis
body: <p>It seems I am getting lost in something potentially silly.
   I have an n-dimensional numpy array, and I want to multiply it with a vector (1d array) along some dimension (which can change!).
  As an example, say I want to multiply a 2d array by a 1d array along axis 0 of the first array, I can do something like this:</p>
  
  <pre><code>a=np.arange(20).reshape((5,4))
  b=np.ones(5)
  c=a*b[:,np.newaxis]
  </code></pre>
  
  <p>Easy, but I would like to extend this idea to n-dimensions (for a, while b is always 1d) and to any axis. In other words, I would like to know how to generate a slice with the np.newaxis at the right place. Say that a is 3d and I want to multiply along axis=1, I would like to generate the slice which would correctly give:</p>
  
  <pre><code>c=a*b[np.newaxis,:,np.newaxis]
  </code></pre>
  
  <p>I.e. given the number of dimensions of a (say 3), and the axis along which I want to multiply (say axis=1), how do I generate and pass the slice:</p>
  
  <pre><code>np.newaxis,:,np.newaxis
  </code></pre>
  
  <p>Thanks.</p>