[Numpy-discussion] Matlab/Numpy index order

Robert Kern robert.kern@gmail....
Tue May 12 15:02:24 CDT 2009

On Tue, May 12, 2009 at 14:55, Ryan May <rmay31@gmail.com> wrote:
> On Tue, May 12, 2009 at 2:51 PM, brechmos <craig@brechmos.org> wrote:
>> So, in Numpy I have to reshape it so the "slices" are in the first
>> dimension.  Obviously, I can do a b.transpose( (1,2,0) ) to get it to look
>> like Matlab, but...
>> I don't understand why the index ordering is different between Matlab and
>> Numpy.  (It isn't a C/Fortran ordering thing, I don' think).
> Actually, that's precisely the reason.

To expand on this comment, when Matlab was first released, it was
basically just an interactive shell on top of FORTRAN routines from
LAPACK and other linear algebra *PACKs. Consequently, it standardized
on FORTRAN's column-major format.

While numpy isn't really beholden to C's ordering for multidimensional
arrays (numpy arrays are just blocks of strided memory, not x[i][j][k]
arrays of pointers to arrays of pointers to arrays), we do want
consistency with the equivalent nested Python lists, and that does
imply row-major formatting by default.

Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco

More information about the Numpy-discussion mailing list