This is related to several questions that discuss the speed of numpy vs Matlab. However most of them have several matrix operations than a single operation. E.g. Difference on performance between numpy and matlab
For me, the time numpy take just to invert a random matrix is approximately 5 times slower than that of matlab.
Here is the matlab script,
N = 1000;
B = randn(N,N);
h = tic;
T = 40;
for i=1:40
Rinv = (B)^(-1);
end
toc(h)/40
This gives an average values of 0.08 seconds approximately.
While this python script gives 0.4 seconds (approx).
import numpy as np
from numpy import linalg as LA
import time
N=1000
R = np.random.random((N,N))
T=40
t1 = time.clock()
for i in range(0,T):
Rinv = LA.inv(R)
t2 = time.clock()
print 'avg time for inverse ',(t2-t1)/T
Is there any reason for this, or anyway to improve python performance ? I have already implemented my work on Python and I am worried whether I will have to port all my code to matlab. I am working on Ubuntu 16.04, Python 2.7, Matlab R2016b.
I have read that the time
is not a good module for execution time comparisons, I feel this is something more than that.