title: Efficient product of 1D array and 3D array along one dimension - NumPy
body: <p>I have two numpy arrays: </p>
  
  <ul>
  <li>A 1D array called t of shape (70L,) with element called let s say ti</li>
  <li>A 3D array called I with shape (70L, 1024L, 1024L), with each elements called Ii. Ii are thus of dimension (1024L, 1024L)</li>
  </ul>
  
  <p>I would like to make a product of the two array along the first dimension, i.e.:</p>
  
  <pre><code>tI = t1*I1,t2*I2,...,tN*IN
  </code></pre>
  
  <p>such as to obtain again a new array of dimension (70L, 1024L, 1024L) and then take the sum along the first dimension in order to obtain an array of dimension  (1024L, 1024L):</p>
  
  <pre><code>tsum = t1*I1 + t2*I2 + ... +tN*IN
  </code></pre>
  
  <p>For the moment I am satisfied with doing the following:</p>
  
  <pre><code>tI = np.asarray([t[i]*I[i,:,:] for i in range(t.shape[0])])
  tsum = np.sum(tI,axis=0)
  </code></pre>
  
  <p>But it is going to be a bit slow is the dimensions of my array are increasing. 
  I was wondering if there exist a numpy or scipy function, more optimized for that particular task? </p>
  
  <p>Thanks in advance of any link or information. </p>
  
  <p>Greg </p>