From: Stefan v. d. W. <st...@su...> - 2006-10-18 02:22:47
|
On Tue, Oct 17, 2006 at 07:53:11PM -0600, Travis Oliphant wrote: > Stefan van der Walt wrote: > > Hi all, > > > > Some of you may have seen the interesting thread on Fortran-ordering > > earlier. I thought it might be fun to set up a short quiz which test= s > > your knowledge on the topic. > > > > If you're up for the challenge, take a look at > > > > http://mentat.za.net/numpy/quiz > > > > I won't be held liable for any emotional trauma caused, self-inflicte= d > > wounds or brain-core meltdowns. > > =20 >=20 > Cute (especially the comment if you get them all right). I'm not sure= =20 > if this quiz is a veiled complaint about the rules for Fortran ordering= =20 > or not ;-) If it is, it is very tactfully disguised ;) Actually, I was just trying to figure out how Fortran ordering works and thought others might be interested. I reckoned you would be the only one to get 100%, although now you've explained the rules so clearly a couple of other might grasp for the holy grail too. > In my mind the Fortran ordering rules are consistent (if not completely= =20 > bug-free). You just have to get the right idea of what is meant by th= e=20 > order argument when you use it. If you think you are having trouble=20 > figuring out the rules, think of the trouble it was to figure out what=20 > they should be and then to code them up. My sympathies (no, really). > 2) On reshaping, the order argument specifies how you think the array i= s=20 > organized. Whenever you make a significant reshape you are telling the= =20 > computer to re-interpret the chunk of data in a different way, it makes= =20 > a big difference as to how you think about that chunk of data. Do you=20 > think of it as organized rows-first (C-order) or columns-first=20 > (Fortran-order). The order argument allows you to specify how you=20 > think about it and indicates the 1-d indexing order of the array. It=20 > also fills in the newly-shaped array in exactly that same order. =20 > Semantically, one could technically separate those two concepts and hav= e=20 > one order argument that specifies how you think about the input and=20 > another that specifies how you think about the output. But, I really=20 > didn't want to go there and couldn't see a real advantage to that. So,= =20 > the single order argument specifies how you think about both. Thanks for the detailed overview (we should put it on the wiki). Another thing I'm wondering about: when exactly does reshape need to make copies? One last case, which confuses me still (probably because it is 04:16am): In [41]: x =3D N.array([[0,1,2],[3,4,5]],order=3D'F') In [42]: x Out[42]:=20 array([[0, 1, 2], [3, 4, 5]]) I assume the data is now stored in memory as [0 3 1 4 2 5] (column-wise) If I now do x.reshape((3,2),order=3D'C') i.e. take that block of memory, assume it is in 'C' order, and make its shape (3,2), I expect [[0 3] [1 4] [2 5]] but get [[1 2] [3 4] [5 6]] I'm obviously missing something trivial -- I'll try again tomorrow. Cheers St=E9fan |