
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

On Nov 25, 2014 9:30 AM, "Michael Käppler" <xmichael-k@web.de> wrote:
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
Is this something that might be moved to github so it would be easier to submit changes?

+1 On Nov 25, 2014 10:30 AM, "Todd" <toddrjen@gmail.com> wrote:
On Nov 25, 2014 9:30 AM, "Michael Käppler" <xmichael-k@web.de> wrote:
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
Is this something that might be moved to github so it would be easier to submit changes?
_______________________________________________ SciPy-Dev mailing list SciPy-Dev@scipy.org http://mail.scipy.org/mailman/listinfo/scipy-dev
participants (3)
-
Juan Luis Cano
-
Michael Käppler
-
Todd