In [1]:
import numpy as np
import numpy.linalg as npl
from sympy import *
In [2]:
dim = 50
In [3]:
M = randMatrix(dim,dim)/float(dim)
x = randMatrix(dim,1)/float(dim)
u = M*x
In [4]:
%%timeit
xx = M.LUsolve(u)
xx - x 
2.45 s ± 5.77 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
In [5]:
%%timeit
xx = M.inv() * u
xx - x    
4.89 s ± 21.2 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
In [6]:
A = matrix2numpy(M).astype(float)
y = matrix2numpy(x).astype(float)
v = A@y
In [7]:
%%timeit
yy = npl.solve(A,v)
yy - y
101 µs ± 1.46 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)