Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is MATLAB faster than Python?

I want to compute magnetic fields of some conductors using the Biot–Savart law and I want to use a 1000x1000x1000 matrix. Before I use MATLAB, but now I want to use Python. Is Python slower than MATLAB ? How can I make Python faster?

EDIT: Maybe the best way is to compute the big array with C/C++ and then transfering them to Python. I want to visualise then with VPython.

EDIT2: Which is better in my case: C or C++?

like image 688
kame Avatar asked Jan 25 '10 14:01

kame


People also ask

Is MATLAB or Python better?

What are the major differences between MATLAB and Python? Python is a high-level language, it is more user friendly, more readable and more portable. MATLAB is a low-level language and not good at some algorithms such as bioinformatics.

Which is faster MATLAB or NumPy?

The time matlab takes to complete the task is 0.252454 seconds while numpy 0.973672151566, that is almost four times more.

Is Python going to replace MATLAB?

For all of these reasons, and many more, Python is an excellent choice to replace MATLAB as your programming language of choice. Now that you're convinced to try out Python, read on to find out how to get it on your computer and how to switch from MATLAB! Note: GNU Octave is a free and open-source clone of MATLAB.

Is MATLAB more difficult than Python?

* Secondly, compared with MATLAB, Python is better to find out and more rigorous programing language. It allows users to jot down code that's easier to read and maintain. * Ultimately, MATLAB chiefly focuses on engineering and technical computing.


1 Answers

You might find some useful results at the bottom of this link

http://wiki.scipy.org/PerformancePython

From the introduction,

A comparison of weave with NumPy, Pyrex, Psyco, Fortran (77 and 90) and C++ for solving Laplace's equation.

It also compares MATLAB and seems to show similar speeds to when using Python and NumPy.

Of course this is only a specific example, your application might be allow better or worse performance. There is no harm in running the same test on both and comparing.

You can also compile NumPy with optimized libraries such as ATLAS which provides some BLAS/LAPACK routines. These should be of comparable speed to MATLAB.

I'm not sure if the NumPy downloads are already built against it, but I think ATLAS will tune libraries to your system if you compile NumPy,

http://www.scipy.org/Installing_SciPy/Windows

The link has more details on what is required under the Windows platform.

EDIT:

If you want to find out what performs better, C or C++, it might be worth asking a new question. Although from the link above C++ has best performance. Other solutions are quite close too i.e. Pyrex, Python/Fortran (using f2py) and inline C++.

The only matrix algebra under C++ I have ever done was using MTL and implementing an Extended Kalman Filter. I guess, though, in essence it depends on the libraries you are using LAPACK/BLAS and how well optimised it is.

This link has a list of object-oriented numerical packages for many languages.

http://www.oonumerics.org/oon/

like image 89
petantik Avatar answered Sep 24 '22 02:09

petantik