Python eigenvalue computations run much slower than those of MATLAB on my computer. Why?

I would like to compute the eigenvalues of large-ish matrices (about 1000x1000) using Python 2.6.5. I have been unable to do so quickly. I have not found any other threads addressing this question.

When I run

a = rand(1000,1000);
tic;
for i =1:10
    eig(a);
end
toc;

in MATLAB it takes about 30 seconds. A similar test in Python requires 216 seconds. Running it through R using RPy did not speed up the computation appreciably. A test in Octave took 93 seconds. I am a bit baffled at the difference in speed.

The only instance of a question like this one I can find online is this, which is several years old. The poster in that question has a different Python directory structure (which I attribute to the age of the post, although I could be mistaken), so I have not been confident enough to attempt to follow the instructions posted by the correspondent.

My package manager says that I have LAPACK installed, and I am using NumPy and SciPy for the Python calculations:

from numpy import *
from scipy import *
from numpy.linalg import *
import time

a = randn(1000,1000)
tic = time.clock()
for i in range(0,10):
    eig(a)
toc = time.clock()
print "Elapsed time is ", toc-tic

I am pretty new to Python, so I may have done something silly. Please let me know if I need to provide any more information.

13
задан eat 18 May 2011 в 23:19
поделиться