Newbie Question

Chris Barker chrishbarker at home.net
Mon Jun 4 17:09:33 EDT 2001


John Cristion wrote:
> 
> MATLAB vs. PYTHON
> Please compare and contrast for this MATLAB user and newbie to PYTHON
> (beyond the obvious cost, etc. issues)

There's a lot to be said about this, but here are few of my thoughts as
a previous heavy MATLAB user, and current heavy Python user (for
somewhat, but not entirely, different things).

MATLAB has a much more complete set of pre-existing numeric functions

MATLAB has much better plotting facilities. All the ones for Python are
wrappers around something else, none of them are truly cross platform,
and all of which are harder to use thatn MATLAB.

Python is much better for doing anything other than number
crunching/data visualization (i.e. making a GUI, text crunching, etc.)

NumPy Arrays have some nifty features that MATLAB's don't: array
broadcasting, for example. I really like being able to write:

>>> x = array([1,2,3,4])
>>> x
array([1, 2, 3, 4])
>>> y = array([[5],[6],[7],[8]])
>>> y
array([[5],
       [6],
       [7],
       [8]])
>>> z = x*y
>>> z
array([[ 5, 10, 15, 20],
       [ 6, 12, 18, 24],
       [ 7, 14, 21, 28],
       [ 8, 16, 24, 32]])
>>>

Rather than:
>> x = [1,2,3,4]
x =
     1     2     3     4
>> y = [5;6;7;8]
y =
     5
     6
     7
     8
>> [X,Y] = meshgrid(x,y)
X =
     1     2     3     4
     1     2     3     4
     1     2     3     4
     1     2     3     4
Y =
     5     5     5     5
     6     6     6     6
     7     7     7     7
     8     8     8     8
>> z = X.*Y
z =
     5    10    15    20
     6    12    18    24
     7    14    21    28
     8    16    24    32
>>
The constant need for meshgrid is annoying, and memory wasteful.

Numeric arrays can be any of a large number of types, not just doubles.
This can save a whole lot of memory when you need just small integers,
for example.

NumPy has much better facilities for dealing with arrays of greater than
two dimensions.

NumPy used element-wise operations by default, rather than matric
operations. THis makes if more awkward to do matrix operations, but I
find I do element-wise operations far more often.

Python has much better object-orientation, and is generally a nicer,
more powerful general perpose language.

That's a few quick comments.

If you're going to be using Python for MATLAB lie activities, take a
look on the web for assorted useful stuff. Here area couple of links to
get you started:

http://scipy.org/
http://MatPy.sourceforge.net/

Have fun!

-- 
Christopher Barker,
Ph.D.                                                           
ChrisHBarker at home.net                 ---           ---           ---
http://members.home.net/barkerlohmann ---@@       -----@@       -----@@
                                   ------@@@     ------@@@     ------@@@
Oil Spill Modeling                ------   @    ------   @   ------   @
Water Resources Engineering       -------      ---------     --------    
Coastal and Fluvial Hydrodynamics --------------------------------------
------------------------------------------------------------------------



More information about the Python-list mailing list