[SciPy-Dev] [Wiki] NumPy / Matlab-Cheatsheet

Michael Käppler xmichael-k at web.de
Mon Nov 24 02:42:39 EST 2014


Hi guys,
thanks for this great cheatsheet you provided on 
wiki.scipy.org/NumPy_for_Matlab_Users.
I'm not allowed to edit the wiki, so I would like to propose an addition 
regarding different array shaping conventions: Consider f.e. a Matlab 
zeros(1, 4).
If I'm right, this results in a [0 0 0 0] or in something that Matlab 
treats like a 1D-Array if it makes sense. You can f.e. do 
diag(ones(1, 4)) and you get a matrix.
However, NumPy zeros((1,4)) results in [[0 0 0 0]], which is 2D and if you 
try to do diag(ones((1,4))) you will get [1], which is obviously different 
behaviour compared to Matlab.
NumPy zeros(4) yields [0 0 0 0] which seems to me is the correct 
equivalent. Other Matlab commands that use this array shaping syntax are 
also affected in the same way.
I recently ran into this issue while porting some Matlab code to NumPy.

Have a nice week,
Michael




More information about the SciPy-Dev mailing list