title: Numpy: Avoiding nested loops to operate on matrix-valued images
body: <p>I am a beginner at python and numpy and I need to compute the matrix logarithm for each "pixel" (i.e. x,y position) of a matrix-valued image of dimension NxMx3x3. 3x3 is the dimensions of the matrix at each pixel.</p>
  
  <p>The function I have written so far is the following:</p>
  
  <pre><code>def logm_img(im):
      from scipy import linalg
      dimx = im.shape[0]
      dimy = im.shape[1]
      res = zeros_like(im)
      for x in range(dimx):
          for y in range(dimy):
              res[x, y, :, :] = linalg.logm(asmatrix(im[x,y,:,:]))
      return res
  </code></pre>
  
  <p>Is it ok?
  Is there a way to avoid the two nested loops ?</p>