[Numpy-discussion] Matlab -> NumPy translation and indexing

David Cournapeau david@ar.media.kyoto-u.ac...
Mon Mar 5 21:38:03 CST 2007

David Koch wrote:
> Hello,
> I am trying to translate some Matlab code to NumPy. I started reading 
> the NumPy book and, yeah it's a very long read :-/ One thing I am 
> completely confused about are the concpets of "basic" vs. "advanced" 
> indexing. Are there some good examples out there where for the same 
> piece of code - Matlab and NumPy are compared? I feel looking at those 
> maybe more helpful to get me started than an in-depth study of the 
> book. I already read "Numpy for Matlab users" and at a glance it 
> doesn't seem to contain equivalents to all the common indexing 
> operations you'd do in Matlab.
I have been there too ("long time" user of matlab, numpy convert for one 
year now), and two links which help me a lot to have a direct mapping 
between matlab and python at the beginning are:


Generally, except if you are doing a lot of linear algebra, and have to 
write a lot things like dot(a, dot(b, dot(c, d))), my experience is that 
you should avoid thinking the "matlab" way, and use nd array (that is 
vector is rank 1, matrices are rank 2, etc...). It means that sometimes, 
you will have to be more specific about some things, but make some other 
things easier. For me (signal processing), once I switched to numpy way 
of thinking, I found it easier to use nd arrays.


More information about the Numpy-discussion mailing list