What does Fortran order mean?

Stefan van der Walt stefan at sun.ac.za
Tue Oct 17 11:44:10 CDT 2006


On Tue, Oct 17, 2006 at 10:01:51AM -0600, Travis Oliphant wrote:
> Charles R Harris wrote:
> 
> > Travis,
> >
> > I note that
> >
> > >>> a = arange(6).reshape(2,3,order='F')
> > >>> a
> > array([[0, 1, 2],
> >        [3, 4, 5]])
> >
> > Shouldn't that be 3x2? Or maybe [[0,2,4],[1,3,5]]? Reshape is making a 
> > copy, but flat, flatten, and tostring all show the elements in 'C' 
> > order. I ask because I wonder if changing the order can be used to 
> > prepare arrays for input into the LaPack routines.
> 
> 
> The order argument to reshape means (how should the big-chunk of data be 
> interpreted when you reshape).  So, yes, this should be 
> [[0,2,4],[1,3,5]].  It is a bug that it does not do the right thing in 
> this case.

A bit counter-ituitive (I somehow expect reshape to return an array
that satisfies all the constraints specified as parameters -- i.e.
shape and order in memory), but consistent with Numeric.

What confuses me is that, if you call the array constructor, you get

In [2]: N.array(N.array([[1,2,3],[4,5,6]]),order='F')
Out[2]: 
array([[1, 2, 3],
       [4, 5, 6]])

so here 'order' means something else.

So then you do

x = N.array([[0,1,2],[3,4,5]],order='F')
x.reshape((2,3),order='C')

and you get

array([[0, 1, 2],
       [3, 4, 5]])

Hmm.

Cheers
Stéfan

-------------------------------------------------------------------------
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




More information about the Numpy-discussion mailing list