title: Numpy broadcasting in z direction
body: <p>In a machine learning context, I need to do a per-element multiplication. To do this efficiently, I need to broadcast elements of a 3D tensor in a particular way such that each 2x2 matrix is repeated n times, as shown by the following example with n=2:</p>
  
  <pre><code>import numpy as np
  
  a = np.linspace(1,12,12)
  a = a.reshape(3,2,2)
  
  # what to put here?
  &lt;some statements&gt;
  
  print a
  
  # result:
  [[[  1.   2.]
    [  3.   4.]]
  
   [[  1.   2.]
    [  3.   4.]]
  
   [[  5.   6.]
    [  7.   8.]]
  
   [[  5.   6.]
    [  7.   8.]]
  
   [[  9.  10.]
    [ 11.  12.]]
  
   [[  9.  10.]
    [ 11.  12.]]]
  </code></pre>
  
  <p>What statement(s) would do the job?</p>
  
  <p>Thanks!</p>