title: Multiplying multidimensional array in python
body: <p>I have two arrays:</p>
  
  <pre><code>L, M, N = 6, 31, 500
  A = np.random.random((L, M, N))
  B = np.random.random((L, L))
  </code></pre>
  
  <p>I am trying to get an array C such that:</p>
  
  <pre><code>C = B * A
  
  C has dimension  [L, M, N]  
  </code></pre>
  
  <p>I tried answer posted at this <a href="https://stackoverflow.com/questions/23527738/multiply-multidimensional-arrays-in-python">link</a> but it hasn't given me the desired output.</p>
  
  <p>A for loop version of above code is:</p>
  
  <pre><code>L, M, N = 6, 31, 500
  A = np.random.random((L, M, N))
  B = np.random.random((L, L))
  
  z1 = []
  for j in range(M):
      a = np.squeeze(A[:, j, :])
      z1.append(np.dot(B, a))
  
  z2 = np.stack(z1)
  </code></pre>