title: Efficient iteration over 3D array?
body: <p>I am using Python and Numpy to do some data analysis.</p>
  
  <p>I have a large 3D matrix (NxNxN), where each cell is again a matrix, this time a 3x3 matrix. Calling the matrix <code>data</code>, it looks like this:</p>
  
  <pre><code>data[N,N,N,3,3]  
  </code></pre>
  
  <p>I need to find the eigenvalues of all the 3x3 matrices, and for that I use Numpy's <code>eigvals</code> routine, but it takes ages to do. Right now I pretty much do this:</p>
  
  <pre><code>for i in range(N):
      for j in range(N):
          for k in range(N):
              a = np.linalg.eigvals(data[i,j,k,:,:])
  </code></pre>
  
  <p>For N = 256, this takes about an hour. Any ideas on how to make this more efficient?</p>
  
  <p>Many thanks for any suggestions!</p>