title: Multiply together list of matrices in Numpy
body: <p>I'm looking for an efficient way to multiply a list of matrices in Numpy. I have a matrix like this:</p>
  
  <pre><code>import numpy as np
  a = np.random.randn(1000, 4, 4)
  </code></pre>
  
  <p>I want to matrix-multiply along the long axis, so the result is a 4x4 matrix. So clearly I can do:</p>
  
  <pre><code>res = np.identity(4)
  for ai in a:
      res = np.matmul(res, ai)
  </code></pre>
  
  <p>But this is super-slow. Is there a faster way (perhaps using <code>einsum</code> or some other function that I don't fully understand yet)?</p>