From: Charles R H. <cha...@gm...> - 2006-10-18 02:21:06
|
On 10/17/06, Travis Oliphant <oli...@ie...> wrote: > > Charles R Harris wrote: > > > > > > On 10/17/06, *Lisandro Dalcin* <da...@gm... > > <mailto:da...@gm...>> wrote: > > > > I was surprised by this > > > > In [14]: array([[1,2,3],[4,5,6]]).reshape((3,2),order='F') > > Out[14]: > > array([[1, 5], > > [4, 3], > > [2, 6]]) > > > > > > This one still looks wrong. > > > > In [15]: array([1,2,3,4,5,6]).reshape((3,2),order='F') > > Out[15]: > > array([[1, 2], > > [3, 4], > > [5, 6]]) > > > > > > > > This one is fixed, > > > > In [3]: array([[1,2,3,4,5,6]]).reshape((3,2),order='F') > > Out[3]: > > array([[1, 4], > > [2, 5], > > [3, 6]]) > > > > I also don't understand why a copy is returned if 'F' just fiddles > > with the indices and strides; the underlying data should be the same, > > just the view changes. FWIW, I think both examples should be returning > > views. > > You are right, it doesn't need to. My check is not general enough. > > It can be challenging to come up with a general way to differentiate the > view-vs-copy situation and I struggled with it. In this case, it's the > fact that while self->nd > 1, the other dimensions are only of shape 1 > and so don't really matter. If you could come up with some kind of > striding check that would distinguish the two cases, I would appreciate > it. I suppose the problem is mostly in discontiguous arrays. Hmmm..., this isn't too different that reshaping the transpose. a.reshape((m,n),order='F' ~ a.reshape((n,m)).T.reshape(m,n) for instance: In [26]: a Out[26]: array([[1, 2, 3], [4, 5, 6]]) In [27]: a.reshape((3,2)).T.reshape((2,3)) Out[27]: array([[1, 3, 5], [2, 4, 6]]) In [28]: a.reshape((2,3), order='F') Out[28]: array([[1, 2, 3], [4, 5, 6]]) Where I actually think the second reshape is correct and the third incorrect. This has the advantage that *all* the steps return views. Chuck |