# The NumPy Fortran-ordering quiz

Charles R Harris charlesr.harris at gmail.com
Wed Oct 18 16:48:22 CDT 2006

```On 10/18/06, George Nurser <gnurser at googlemail.com> wrote:
>
> > > None of the LaPack stuff seems to use the Fortran stuff, they just
> > > transpose and copy.
>
> You've got me worried here. I have assumed that when you start with a
> c-contiguous array, a, with say,a.shape = (m,n), if you use the
> transpose as an argument to a fortran routine which requires an mxn
> size array, then no copying is required.
>
> This seems to work for me -- the transpose *does* have fortran order.

Nope. The result is an (n,m) array in fortran order, not an (m,n) array in
fortran order.

In [52]:a = array([[1,2,3],[4,5,6]])

In [53]:a.transpose().flags
Out[53]:
CONTIGUOUS : False
FORTRAN : True
OWNDATA : False
WRITEABLE : True
ALIGNED : True
UPDATEIFCOPY : False

In [54]:a.transpose().shape
Out[54]:(3, 2)

Looks like what you want is either fastcopyandtranspose or the order flag.

In [56]:fastCopyAndTranspose(a).flags
Out[56]:
CONTIGUOUS : True
FORTRAN : False
OWNDATA : True
WRITEABLE : True
ALIGNED : True
UPDATEIFCOPY : False

which is a (n,m) array in c order, i.e., an (m,n) array in fortran order. Or

In [57]:array(a, order='F').flags
Out[57]:
CONTIGUOUS : False
FORTRAN : True
OWNDATA : True
WRITEABLE : True
ALIGNED : True
UPDATEIFCOPY : False

which is a (m,n) array in fortran order.

Also, in f2py, if I use -DF2PY_REPORT_ON_ARRAY_COPY=1 I receive no

f2py takes care of the ordering, which is one reason why it is so useful.

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20061018/692674d7/attachment.html
-------------- 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