title: Efficient 3x3 and 2x2 Determinants in NumPy
body: <p>I have a large numpy array, <code>arr</code>, of shape <code>(N, D, M, D)</code> where <code>D</code> is either two or three.  The array can be thought of as a block of <code>(D,D)</code> matrices blocked together in the <code>N</code> and <code>M</code> dimensions.  I wish to take the determinant of each of these <code>(D,D)</code> matrices:</p>
  
  <pre><code>out = np.empty((N,M))
  for i in xrange(N):
      for j in xrange(M):
          out[i,j] = np.linalg.det(arr[i,:,j,:])
  </code></pre>
  
  <p>The only problem is that <code>np.linalg.det</code> does not special-case small matrices and so does a complete BLAS call and LU factorization for each block.  Indeed, for a 2 by 2 matrix <code>np.linalg.det</code> takes ~40us on my recent Core i7 system.  What are my options for improving the performance of this fragment?</p>