Hello,

 

I was surprised to discover recently that the RESHAPE function in Python and Matlab do not yield the same result. In fact, Python reshapes along the rows while Matlab does it along the columns.

 

For example, the Matlab code:

>> a=(0:19);

>> reshape(a,5,4)

 

ans =

 

     0     5    10    15

     1     6    11    16

     2     7    12    17

     3     8    13    18

     4     9    14    19

 

And the Python equivalent:

>>> a=arange(20)

>>> reshape(a,(5,4))

[[ 0, 1, 2, 3, ]

 [ 4, 5, 6, 7, ]

 [ 8, 9,10,11, ]

 [12,13,14,15,]

 [16,17,18,19,]]

 

To obtain the same result, I should write:

>>> transpose(reshape(a,(4,5)))

 

Does anyone have an explanation for this? Is it possible to change the axis priority like e.g., in concatenate?

 

Thank you,

 

Dimitri D'Or