[SciPy-user] Vectorized Approach to Matrix Inversion
Josh Lawrence
josh.k.lawrence@gmail....
Wed Nov 12 11:23:26 CST 2008
Hey all,
I have a NxNxP array. Let's call it foo. foo[:,:,p] contains a matrix
I want to invert (or to solve in the Ax = b fasion). Is there a pure
python/scipy way to compute an array bar without loops such that it
would be equivalent to the following?
import scipy.linalg as la
import numpy as np
bar = np.zeros((N, N, P)) + 0j
for i in range(0,P):
bar[:,:,i] = la.inv(foo[:,:,i])
Or in the Ax = b sense (with b an NxP array, and A NxNxP):
import scipy.linalg as la
import numpy as np
x = np.zeros((N, P)) + 0j
for i in range(0,P):
x[:,i] = la.solve(A[:,:,i], b[:,i])
I realize I could write some fortran code to do this or even use
cython, but it would be nice if I could do this without needing to
compile some extra code. As a summary, does anyone know how to compute
the above (either example, but preferably both) without using loops?
Cheers,
Josh
More information about the SciPy-user
mailing list