The NumPy Fortran-ordering quiz

Charles R Harris charlesr.harris at gmail.com
Wed Oct 18 17:48:22 EDT 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
> alert of any copy.


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://mail.python.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
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
-------------- next part --------------
_______________________________________________
Numpy-discussion mailing list
Numpy-discussion at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/numpy-discussion


More information about the NumPy-Discussion mailing list