Solving Ax=B by inverting matrix A can be lot more computationally intensive than solving directly.
Python’s NumPy has linalg.solve(A, B), which returns the ‘x’ array
x = numpy.linalg.solve(A,B)
It uses a LU decomposition method for solving (not inversion).
SVD can also be used to solve without the need for inverting matrix A.
Here’s the function
def svdsolve(a,b): import numpy as np u,s,v = np.linalg.svd(a) c = np.dot(u.T,b) w = np.linalg.solve(np.diag(s),c) x = np.dot(v.T,w) return x
The following screencast shows the two methods of solving Ax=B in action.
You might like the post titled Beautiful Demo of How SVD works!