[Numpy-discussion] Matlab page on scipy wiki

Vidar Gundersen vidar+list at 37mm.no
Fri Mar 3 00:29:06 CST 2006


===== Original message from Sebastian Haase | 3 Mar 2006:
> I noted on
> http://www.scipy.org/Wiki/NumPy_for_Matlab_Users


there is one other difference, which i think is not so
easily seen, and not noted on the above mentioned page:

a(:) in Matlab, will flatten the array by following each
column, whereas a.flatten() in NumPy will walk through the
matrix like we read comics, putting each row after each other:


In [1]: a = arange(9).reshape(3,-1)

In [2]: a
Out[2]: 
array([[0, 1, 2],
       [3, 4, 5],
       [6, 7, 8]])

In [3]: a.flatten()
Out[3]: array([0, 1, 2, 3, 4, 5, 6, 7, 8])

In [4]: a.flatten(1)    # same output as a(:) in Matlab
Out[4]: array([0, 3, 6, 1, 4, 7, 2, 5, 8])


the user have to be aware of this when reshaping matrices also.


I've updated my similar Matlab-Python reference to cover NumPy:
http://37mm.no/mpy/matlab-numpy.html
(example plot graphics is not yet included in the HTML version.)

See other command equivalents, like IDL or R commands in NumPy, here:
http://37mm.no/matlab-python-xref.html



Vidar___




More information about the Numpy-discussion mailing list