# [SciPy-user] matrix inversion time (Python vs MATLAB)

Ch B Komaki bkomaki@yahoo....
Fri Jan 9 14:17:38 CST 2009

```Hallo,
Despite the comparing of th t wo software is possible, but the fact is Python is designed for Array but Matlab is oruginally for matrix.

--- On Fri, 1/9/09, zzzz <migita@gmail.com> wrote:
From: zzzz <migita@gmail.com>
Subject: [SciPy-user] matrix inversion time (Python vs MATLAB)
To: scipy-user@scipy.org
Date: Friday, January 9, 2009, 9:17 PM

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.
_______________________________________________
SciPy-user mailing list
SciPy-user@scipy.org
http://projects.scipy.org/mailman/listinfo/scipy-user

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/scipy-user/attachments/20090109/aefac42f/attachment.html
```