The NumPy Fortran-ordering quiz

Charles R Harris charlesr.harris at
Tue Oct 17 23:26:17 CDT 2006

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:

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

Now, either CONTIGUOUS is in error, because it really *is* fortran
contiguous (but not c contiguous), or the array cannot be passed to a
fortran routine that expects fortran ordering, or CONTIGUOUS refers to C
addressing, which we already know is not contiguous, in which case we feel
uncertain. Note that knowing the answer matters if I want to call a fortran
routine with this by pulling out the data pointer. The fortran routine could
be in a library, or maybe in the LaPack wrapper, but whatever, it hasn't
been wrapped by f2py that takes care of such details.

This also looks fishy:

In [93]: asfortranarray(array([[1,2,3],[4,5,6]], dtype=int8))
array([[1, 2, 3],
       [4, 5, 6]], dtype=int8)

In [96]: asfortranarray(array([[1,2,3],[4,5,6]], dtype=int8)).flags
  FORTRAN : True
  OWNDATA : True
  ALIGNED : True

because the docstring says:

asfortranarray(a, dtype=None)
    Return 'a' as an array laid out in Fortran-order in memory.

Which doesn't seem to be the case here. I am beginning to wonder if we
really need fortran order, seems that a few well chosen interface routines
would fill the need and avoid much confusion.

-------------- next part --------------
An HTML attachment was scrubbed...
-------------- next part --------------
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
-------------- next part --------------
Numpy-discussion mailing list
Numpy-discussion at

More information about the Numpy-discussion mailing list