title: Iterate over vectors in a multidimensional numpy array
body: <p>I have a 3xNxM numpy array a, and I would like to iterate over the last two axes: a[:,x,y]. The inelegant approach is:</p>
  
  <pre><code>import numpy as np
  a = np.arange(60).reshape((3,4,5))
  M = np. array([[1,0,0],
                 [0,0,0],
                 [0,0,-1]])
  
  for x in arange(a.shape[1]):
      for y in arange(a.shape[2]):
          a[:,x,y] = M.dot(a[:,x,y])
  </code></pre>
  
  <p>Can this be done with nditer? The goal of this is to perform a matrix multiplication on each entry, e.g. a[:,x,y] = M[:,:,x,y].dot(a[:,x,y]). An alternative, MATLAB-style approach would be to reshape a as (3,N*M) and M as (3,3*N*M) and take a dot product, but that tends to eat up a lot of memory.</p>