Matlab -> Python

Ionel Simionescu ionel at psy.uva.nl
Wed Oct 20 04:57:34 EDT 1999


Matti Picus <matti at tx.technion.ac.il> wrote in message
news:380C5017.9852E40 at tx.technion.ac.il...
| Anyone translating matlab syntax to python? Any tutorials on the common
| pitfalls or how to get started
|


I do not translate, using both I might help.

If you can find C/C++ versions of your algorithms, then you will get
automated help from SWIG.

I do not know of a tool for automating / assisting with the Matlab -> Python
translation. If you consider implementing one, you may get a lot of help
from the Python compiler compiler packages, such as kwParsing, or the
regular expressions module.

One may consider two aspects:
1. The general language translation issues, that is regarding
syntax/semantics.
2. Specific functionality, that is numeric library, data visualization and
GUI building functions.

1.
In regard with syntax and semantics, there are significant differences:
- MATLAB always passes matrices by value. In Python, you are in control:
while you normally pass a reference, you can also pass a copy.
- The organization of software elements is quite different. MATLAB basically
does everything with functions. Since version 5, they introduces a mechanism
for overloading, which they call object-orientation. In Python, you will
find the OO concepts implemented more fully and intuitively.

IMO, given this difference, one may do better to re-think the design of
programs before translating.

2.
The Numeric package provides Python with fast array-oriented processing.
The raw speed which may be achieved is very good. In my experience,
Python/Numeric code will run 3-4 times faster than the equivalent MATLAB
code.
However, there are some problems:
- while Matlab is matrix-centric, Numeric is ARRAY-centric. Arrays are not
matrices and it takes a day or two to get used with Numeric's ways. However,
once the click happened you'll be happy again. After one more week you'll be
even happier.
- Numeric's documentation is terse, rather Pythonish and written for
experienced programmers rather than casual users. I'd call it a quick
reference if I'd have time to write a better one. Ask for help.
- the library is limited to rather basic functions. You get full control of
multi-dimensional arrays, some often used math for them but not much else.

Visualization is not very well supported. However, you will find interfaces
to Gnuplot and a number of native packages.  If you need specialized
graphics tightly integrated with your application, chances are that you will
have to get your hands dirty with low-level implementation code.

GUI building is well supported but rather isolated from the visualization
functions.

---------

In my experience, Python offers a larger conceptual pallete and fits much
more naturally with the design of algorithms which need both numeric speed
and elaborated data structures.


I will try to help further if any more specific question.

ionel


-----
Note:
For references to all the names mentioned above, go to http://www.python.org
and do a simple search. Results will pop-up right away.










More information about the Python-list mailing list