The NumPy Fortran-ordering quiz

A. M. Archibald peridot.faceted at
Wed Oct 18 09:30:02 CDT 2006

On 18/10/06, Charles R Harris <charlesr.harris at> wrote:
> On 10/17/06, A. M. Archibald <peridot.faceted at> wrote:
> > On 17/10/06, Charles R Harris <charlesr.harris at> wrote:
> > >
> > >
> > > On 10/17/06, Travis Oliphant <oliphant.travis at > wrote:
> >
> > > > Thus, reshape does the equivalent of a Fortran ravel to [1,4,2,5,3,6]
> > > > and then a Fortran-order based fill of an empty (3,2) array:  giving
> you
> > > > the result.
> > >
> > > Why a Fortran ravel? I am thinking of it as preserving the memory
> layout,
> > > just messing with how it is addressed.
> >
> > Because, to first order, the memory layout is totally irrelevant to a
> > python user.
> >
> > array([[1,2,3],[4,5,6]],order='C')
> > array([[1,2,3],[4,5,6]],order='F')
> >
> > should be nearly identical to the python user.
> So what is the point of having a fortran layout if things are not actually
> layed out in fortran order? As far as I can see, memory layout is the only
> reason for fortran ordering. Now I can sort of see where the fortran ravel
> comes from, because the result can be passed to a fortran routine. And it
> does look like a.ravel('F') is the same as a.T.ravel(). Hmmm. Now I wonder
> about this:

Thins are laid out in Fortran order if you request Fortran order upon
array creation. You just can't see it, normally. Numpy tries hard to
make arrays of all different orders look identical.

Of course, the reason I said "to first order" is that when determining
when to copy and when not to, or when passing arrays to C or Fortran
functions, sometimes it does matter. For example, a typical Fortran
linear algebra routine needs its arrays to be in Fortran order in

> In [62]: array([[1,2,3],[4,5,6]], dtype=int8, order='F').flags
>  Out[62]:
>   CONTIGUOUS : False
>    FORTRAN : True
>   OWNDATA : True
>    WRITEABLE : True
>   ALIGNED : True

Unless you're working with C extensions, it doesn't make much sense to
ever look at flags. The memory layout does not affect normal array
behaviour (including reshape).

A. M. Archibald

Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo

More information about the Numpy-discussion mailing list