top | item 689183

Mathematica vs. Matlab vs. Python

52 points| soundsop | 16 years ago |larssono.com | reply

14 comments

order
[+] gjm11|16 years ago|reply
The title is a bit misleading; it compares the three for one single task only. It's useful as an indication of how a few particular things might be done in Mma, MATLAB and Python, but here are a few reasons to be very cautious about (e.g.) looking at the amount of code involved in each case and leaping to conclusions.

1. It's just a single problem.

2. It happens to be (by accident or design) one that plays right to MATLAB's strengths (matrix manipulation and plotting). Numeric Python and Pylab are aiming at pretty much the same domains. Mathematica, less so.

3. The MATLAB code reads the input data from a MATLAB .mat file (which only MATLAB knows how to read and write). The Mma and Python code gets it from a text file. Curiously, the MATLAB code for reading the data is much shorter than the Mma and Python code for the "same" job.

4. The code is less than perfectly idiomatic. For instance, the Mma code for counting null data occupies 11 lines when it could be one line (and that not terribly long or terribly obscure): numbers = BinCounts[Map[Count[#,Null]&,matrix],{0,genes}] .

5. The MATLAB and Python plotting code just accepts the default options for the plots. The Mma plotting code is full of option-setting. Presumably the author really likes the MATLAB defaults and can't stand the Mma defaults. At least one instance of this option-setting (the repeated DisplayFunction -> Identity) is simply explicitly setting the Mma default.

(About half the difference between the Mma column and the others is accounted for by this gratuitous option-setting.) [NOTE: edited to insert the word "half", which I accidentally omitted.]

The author says "using the wrong tool can cause undue work". That's true, and to some extent his comparison demonstrates this. But it also demonstrates the almost equally obvious principles: "using a tool you don't know how to use well can cause undue work", and "doing unnecessary work just for the sake of making your code longer can cause undue work".

(For the avoidance of doubt: I agree that Mathematica is a poor choice of tool for this job. I think the author of the page could, if he'd bothered, have done a comparison that demonstrates that honestly rather than giving a false impression. He could even have tried them on a variety of tasks, some of which weren't optimized for MATLAB and Python+Numeric+Pylab. But perhaps that would have been "undue work".)

[+] jacquesm|16 years ago|reply
That's a pretty solid argument, I'd hate to play chess against you :)

Posts like these should be attached to the original article.

[+] diN0bot|16 years ago|reply
i'd love to see pictures of the final output, too, in addition to performance results.
[+] stcredzero|16 years ago|reply
3. The MATLAB code reads the input data from a MATLAB .mat file (which only MATLAB knows how to read and write). The Mma and Python code gets it from a text file.

But which are the "native" formats for each environment?

[+] mjtokelly|16 years ago|reply
Note that this article is dated 2005. Much has changed since then--for instance, Python has migrated almost universally from Numeric to NumPy for scientific computation.
[+] aaronsw|16 years ago|reply
I'm not Mathematica's biggest fan, but this is just a smear job. He goes way out of his way to write code to do things that Mathematica does automatically. For example, his 32 lines of bar chart display code can be replaced with:

    BarChart[numbers]
[+] buugs|16 years ago|reply
I agree that he is not a mathematica expert but to be one is a pain, the documentation while good is a pain in the ass to navigate and why in the world with so many functions is there no tab completion.

Most of the naming seems to be okay in matlab but sometimes it would be nice if you could tab and see a list of matches.

and I much prefer matlabs: 'help [function]' to the output of '??[Function]'

[+] sdfx|16 years ago|reply
From the main page:

Using mathematical languages to solve real world problems can offer very different experiences. The results will be the same but using the wrong tool can cause undue work. Here I present a table of three different language solutions to the same problem; Calculating and displaying the Singular Value Decomposition of a set of Micoroarray experiments.

[+] illumen|16 years ago|reply
It's nice comparing the python code from this article to what you can do now.

Modern python/numpy will look more elegant.

Also modern numpy can do GPU, multi core and SIMD optimisations (not out of the box... yet).

There's a few pages on the numpy wiki for converting between the two. However both numpy and matlab expressions often look very similar.