The NumPy Fortran-ordering quiz

A. M. Archibald peridot.faceted at gmail.com
Tue Oct 17 23:25:33 EDT 2006


On 17/10/06, Charles R Harris <charlesr.harris at gmail.com> wrote:
>
>
> On 10/17/06, Travis Oliphant <oliphant.travis at ieee.org> 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. If the storage order
mattered, you'd have to know, every time you used reshape, what order
your matrix was stored in (did it come from a transpose operation, for
example?).

As for why a Fortran ravel rather than a C ravel, that's a simplifying
decision. If you like, you can think of reshape as happening in two
steps:

o1='C'
o2='C'
A.reshape((6,),order=o1).reshape((2,3),order=o2)

The design could have allowed, as Travis Oliphant says, o1!=o2, but
explaining that would have been quite difficult (even more than now, I
mean). And in any case you can use the code above to achieve that, if
you really want.

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
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642




More information about the NumPy-Discussion mailing list