[SciPy-user] matrix inversion time (Python vs MATLAB)
zzzz
migita@gmail....
Fri Jan 9 11:47:44 CST 2009
Hi!
I've made a direct comparison of the time numpy and MATLAB need to
calculate inverse matrix. Since (as far as I know) both call standard
packages such as LAPACK internally, I thought that for large matrices
inversion time should be approximately the same. Contrary to my
expectations, the difference between Python's numpy.linalg.inv and
MATLAB actually diverge (with Python being approximately 6 times
slower than MATLAB for matrices of size 1000).
I use the following "naive" code to estimate inversion time (and a
similar code for MATLAB):
import numpy as np
import time
import csv
def get_rand_mtx(n):
X = np.random.rand(n, n) + 10*np.sqrt(n)*np.eye(n)
# print 'cond = ', np.linalg.cond(X)
return X
def inverse_time(X):
t0 = time.clock()
Xinv = np.linalg.inv(X)
return time.clock()-t0
if __name__ == "__main__":
n_list = range(200, 1000, 10)
times = {}
for n in n_list:
times[n] = inverse_time(get_rand_mtx(n))
Did I miss something?
Thanks.
More information about the SciPy-user
mailing list