def array_inverse(A):
A = np.ascontiguousarray(A, dtype=float)<EOL>b = np.identity(A.shape[<NUM_LIT:2>], dtype=A.dtype)<EOL>n_eq = A.shape[<NUM_LIT:1>]<EOL>n_rhs = A.shape[<NUM_LIT:2>]<EOL>pivots = np.zeros(n_eq, np.intc)<EOL>identity  = np.eye(n_eq)<EOL>def lapack_inverse(a):<EOL><INDENT>b = np.copy(identity)<EOL>pivots = np.zeros(n_eq, np.intc)<EOL>results = np.linalg.lapack_lite.dgesv(n_eq, n_rhs, a, n_eq, pivots, b, n_eq, <NUM_LIT:0>)<EOL>if results['<STR_LIT:info>'] > <NUM_LIT:0>:<EOL><INDENT>raise np.linalg.LinAlgError('<STR_LIT>')<EOL><DEDENT>return b<EOL><DEDENT>return np.array([lapack_inverse(a) for a in A])<EOL>
Compute inverse for each matrix in a list of matrices.
This is faster than calling numpy.linalg.inv for each matrix.