title: Avoiding for loops in numpy arrays multiplications
body: <p>I need to multiply two 3D arrays in an usual way.
  If needed to accomplish my task, I can ''afford'' to permute (change their shape) as I need as they are pretty small in size (less than (1_000, 200, 200) of <code>np.complex128</code>).</p>
  <p>At the moment, I have the following inefficient triple nested for-loop:</p>
  <pre><code>import numpy as np
  result = np.zeros( (640, 39, 20) )
  a = np.random.rand(640, 640, 20)
  b = np.random.rand(39, 640, 20)
  
  for j in range(640):
      for m in range(39):
          for l in range(20):
              result[j, m, l] = (a[j, :, l] * b[m, :, l]).sum()
  </code></pre>
  <p>How can I make the above as efficient as possible using <code>numpy</code>'s magic?</p>
  <p>I know I could use <code>numba</code> and hope that I beat <code>numpy</code> by using compiled code and parallel=True, but I want to see if numpy suffices for my task.</p>
  <p><strong>EDIT: Does it work for a more complex inner for loop as below?</strong></p>
  <pre><code>for l in range(20):
      for m in range(-l, l+1, 1):
          for j in range(640):
              result[j, m, l] = (a[j, :, l] * b[m, :, l]).sum()
  </code></pre>
  <p>After @hpaulj comment, I now understand that the above is not possible.</p>
  <p>Thank you!</p>