Python vs Matlab

Matlab is a popular numerical computing environment and programming language. The concept of Matlab refers to the whole package, including the IDE. The standard library does not contain as much generic programming functionality, but does include matrix algebra and an extensive library for data processing and plotting.

To get similar functionality in Python, you’ll need the NumPy, SciPy and Matplotlib packages. Scipy is a package that has the goal of providing all the other functionality of Matlab, including those in the Matlab toolboxes (which would cost you extra in Matlab). Simulink, however, is one example which is not covered in Python. If you depend on it, you should probably stick to Matlab. Maybe in the future a Python alternative will be created.

Additionally, you’ll need an IDE. Many pythoneers come from a Linux environment and use a Python shell, but people coming from Matlab don’t usually like this (me included). There are a handful of IDE’s available, some of which are for free.

Because Python is open and free, it is very easy for other parties to design packages or other software tools that extend Python. It is possible to create applications using any of the mayor GUI libraries (TK, WX, GTK, QT, …), use OpenGL, drive your USB port, etc. Another example are pyrex to enhance the speed of algorithms by converting Python to C code, and py2exe and the like to create a standalone application from your source.

Advantages of Matlab

Of course, Matlab has its advantages too:

  • It has a solid amount of functions.
  • Simulink is a product which is simply not available elsewhere.
  • It mights also be easier to use for beginners, because the package includes all, while in Python you need to install extra packages and an IDE.
  • It has a large scientific community; it is used on many universities (but few companies have the money to buy a license).

 

Advantages of Python

My reasons for chosing Python:

  • Free. As in speech and as in beer. (It won’t cost you a thing, and you are allowed to view and modify the source.)
  • Beautiful programming language. In my opinion, the python programming language is easier to read and to program than the Matlab programming language. The reason, I think, is because Python was created with the goal of making a beautiful programming language, while Matlab started as a Matrix manipulation package. As I became more familiar with Python, I often was amazed with how well it was designed. There is only one word for that: Beautiful.
  • Powerful. Because it’s so well designed, it’s easier than other languages to transform your ideas into code. But also, Python comes with extensive standard libraries, and has a powerful datatypes such as lists, sets and dictionaries. These really help to organize your data.
  • Namespaces. Matlab now supports namespaces for the functions that you write, but the core of Matlab is without namespaces; every function is defined in the global namespace. Python works with Modules, which you need to import if you want to use them. (For example import scipy.linalg as la; la.cholesky) Therefore Python starts up in under a second. Using namespaces gives structure to a program and keeps it clean and clear. In Python everything is an object, so each object has a namespace itself. This is one of the reasons Python is so good at introspection.
  • Introspection. This is what follows from the object oriented nature of Python. Because a program has a clear structure, introspection is easy. An example aredocstrings: documentation can easily be created in the code right below the definition of a class of function (or at the very start of a module). The documentation of an object (functions are also objects) can be accessed via the .__doc__ property. Note: Matlab has a similar paradigm for inline documentation.
  • String manipulation. This is incredibly easy in Python. What about this line of code which returns a right justified line of 30 characters:
    “I prefer <> over Matlab”.replace(‘<>’,’Python’).rjust(30)
  • Portability. Because Python is for free, your code can run everywhere. And because it’s cross platform, it can also works for costumers that run Linux or mac OS X.
  • Indexing. Python indexing goes as it does in C. Firstly, starting from 0, which is easier in most situations. Secondly, indexing is done using brackets, so you can see the difference between an indexing operation and a function call. You can also select from the end: returns the last two items in the list.
  • Class and function definitions. Functions and classes can be defined anywhere. In one file (whether it is a module or a script) you can design as many functions and classes as you like. You can even define one in the command line if you really want to…
  • Great GUI toolkits. With Python you can create a front-end for your application that looks good and works well. You can chose any of the major GUI toolkits like WX or QT.

Leave a Reply

fifteen + three =