Recently, the number of people, using Python for numerical computation is increasing. I also started to think of migrating some of my scientific work from Matlab to Python. There are some arguments in favor of Python.
First of all it is free. In comparison to Matlab it is a major upside, because the price of just basic Matlab is significant, and purchase of optional toolboxes, further increase total cost of the Mathworks solution. Free Python libraries like: NumPy, SciPy, Matplotlib or IPython, deliver most of the functionality of basic Matlab installation and some functionality of additional toolboxes.
Second, Python is a programming language with interpreters available for almost all platforms. In many systems it is delivered together with the distribution by default. Because of that, it is possible (after installing required libraries) to execute programs written in Python on almost every computer. On the other hand, mainly because of its price, Matlab is most often purchased by scientific institutions, universities or big companies. And mostly with the license restricted to small number of stations or concurrent sessions. Because of that reason, programs written in Matlab can be only executed by people having access to this platform, usually at their work or in school. In this place it should be mentioned, that there is a free alternative to Matlab – Octave. It’s syntax is almost identical to Matlab’s, and any differences in syntax and behavior of functions are considered bugs and they are being fixed. But these two platforms are still not 100% compatible with each other [Porting programs from Matlab to Octave], and even if most of the simple programs in Matlab can be run in Octave, there can be some problems to execute the more complicated ones. Simple Matlab scripts published on this website should execute in Octave 3.2.4 or higher with no errors. There should be no problems with execution of Python scripts (after installation of necessary libraries).
Another upside of Python: it is a full programming language, not an environment dedicated to numerical computations. Because of that, it is easier to use Python for operations not strictly related to computations, when necessary. Large number of dedicated libraries, optimized to specific tasks greatly simplifies the implementation. Python can be used as a scripting language for automation of repeating tasks, and simultaneously, after importing of required libraries, it can be used to perform scientific computations. Many applications has their API in Python. I can easily imagine a situation, where in order to make use of one of my earlier programs in such an application, I just copy with no changes functions and pieces of my Python code. Scripts written in Matlab are useless in this case.
To be fair, there are quite a few upsides of Mathwoks environment also. Matlab is one of the most commonly used platform for computations in the world. It has been used by scientists in many areas for years, and it is a standard in universities. Calculations for scientific publications are performed mostly in Matlab, and blocks of code and algorithms are published in Matlab language. Just because of that it pays off to be familiar with Matlab syntax.
Another advantage of Mathworks platform over Python is, that it delivers one, complete, simple to install environment, having all elements required to work in one place. Right after installation, including automatic installation of purchased toolboxes, the user can run one, complete environment containing: command window, integrated editor, overview of variables in workspaces, debugger, profiler, command history, file browser, on-line help, and even access to internet databases of scripts shared by Matlab community. Workflow is simplified by import and export wizards for common file formats, clipboard data handling or integrated tools for figure manipulation. In my opinion it is a really big Matlab upside, that right after a simple installation user gets complete environment containing many tools simplifying workflow.
Another important upside of Mathwork product is Simulink – environment for simulations and design, integrated with Matlab. Optional dedicated toolboxes can also be purchased for Simulink. Simulink together with Matlab is a powerful platform capable of analysis of dynamic systems behavior, visualization of simulations, data modeling and many others. Currently there is no really concurrent software for Simulink, offering similar capabilities.
There are many pages on the web, comparing Matlab and Python and their pros and cons in different applications. Arguments listed here, pros and cons for each of the two environments are my subjective opinion. I pointed the differences, which I considered significant in my applications – computations in the area of digital signal processing. Other people can have different judgments, based on their own preferences and expectations. In order to evaluate practical aspects of work with these two languages, I would like to perform some computations in both, comparing ease of implementation, execution times etc. As I have no big experience in programming with Python, and on the other hand I would like to do something more interesting than printing some numbers in a loop, I will publish in next posts the examples of usage of both languages to do some simple cases of simulated signals, sound and image processing.
MS Windows users, can download binary versions of many scientific Python libraries on the page: Unofficial Windows Binaries for Python Extension Packages, maintained by Christoph Gohlke. For Linux systems users, it will be easier to use libraries from official repositories or compile the most recent versions from sources.
At the end, links to two open source computation systems: Scilab and SAGE.
This post is also available in: Polish
Comments