From: Gael V. <gae...@no...> - 2006-10-20 11:29:01
|
Hi, There is an operation I do a lot, I would call it "unrolling" a array. The best way to describe it is probably to give the code: def unroll(M): """ Flattens the array M and returns a 2D array with the first column= s=20 being the indices of M, and the last column the flatten M. """ return hstack((indices(M.shape).reshape(-1,M.ndim),M.reshape(-1,1))) Example: >>> M array([[ 0.73530097, 0.3553424 , 0.3719772 ], [ 0.83353373, 0.74622133, 0.14748905], [ 0.72023762, 0.32306969, 0.19142366]]) >>> unroll(M) array([[ 0. , 0. , 0.73530097], [ 0. , 1. , 0.3553424 ], [ 1. , 1. , 0.3719772 ], [ 2. , 2. , 0.83353373], [ 2. , 0. , 0.74622133], [ 1. , 2. , 0.14748905], [ 0. , 1. , 0.72023762], [ 2. , 0. , 0.32306969], [ 1. , 2. , 0.19142366]]) The docstring sucks. The function is trivial (when you know numpy a bit). Maybe this function already exists in numpy, if so I couldn't find it. Elsewhere I propose it for inclusion. Cheers, Ga=EBl |
From: Gael V. <gae...@no...> - 2006-11-12 15:51:11
|
Hi all, I didn't get any answers to this email. Is it because the proposed addition to numpy is not of any interest to anybody apart from me ? Maybe the way I introduced this is wrong. Please tell me what is wrong with this proposition. Regards, Ga=EBl On Fri, Oct 20, 2006 at 01:28:52PM +0200, Gael Varoquaux wrote: > Hi, > There is an operation I do a lot, I would call it "unrolling" a array. > The best way to describe it is probably to give the code: > def unroll(M): > """ Flattens the array M and returns a 2D array with the first colu= mns=20 > being the indices of M, and the last column the flatten M. > """ > return hstack((indices(M.shape).reshape(-1,M.ndim),M.reshape(-1,1))= ) > Example: > >>> M > array([[ 0.73530097, 0.3553424 , 0.3719772 ], > [ 0.83353373, 0.74622133, 0.14748905], > [ 0.72023762, 0.32306969, 0.19142366]]) > >>> unroll(M) > array([[ 0. , 0. , 0.73530097], > [ 0. , 1. , 0.3553424 ], > [ 1. , 1. , 0.3719772 ], > [ 2. , 2. , 0.83353373], > [ 2. , 0. , 0.74622133], > [ 1. , 2. , 0.14748905], > [ 0. , 1. , 0.72023762], > [ 2. , 0. , 0.32306969], > [ 1. , 2. , 0.19142366]]) > The docstring sucks. The function is trivial (when you know numpy a bit= ). > Maybe this function already exists in numpy, if so I couldn't find it. > Elsewhere I propose it for inclusion. > Cheers, > Ga=EBl > -----------------------------------------------------------------------= -- > Using Tomcat but need to do more? Need to support web services, securit= y? > 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 Geron= imo > http://sel.as-us.falkag.net/sel?cmd=3Dlnk&kid=3D120709&bid=3D263057&dat= =3D121642 > _______________________________________________ > Numpy-discussion mailing list > Num...@li... > https://lists.sourceforge.net/lists/listinfo/numpy-discussion |
From: Sven S. <sve...@gm...> - 2006-11-12 17:07:49
|
Gael Varoquaux schrieb: > Hi all, > > I didn't get any answers to this email. Is it because the proposed > addition to numpy is not of any interest to anybody apart from me ? > Maybe the way I introduced this is wrong. Please tell me what is wrong > with this proposition. > Well you didn't mentioned why it would be useful for a broad audience, only that you yourself use it alot. Together with the fact that it's a one-liner this presumably means that it's not exactly a prime candidate for adoption. (I'm just another user, so I'm speculating a bit here based on my reading of past postings on this list.) -sven |
From: Gael V. <gae...@no...> - 2006-11-12 17:12:38
|
You're probably right. Well it would most definitely be useful for all the lads in my lab, but I am not sure this is a broad audience. The use case is when you have a array representing data in an "mgrid" way, and you wnat to apply transformations to the coordinates. It is something I have done and seen done quite often. If I am the only one a the list who see a use for this, then forget it. Ga=EBl On Sun, Nov 12, 2006 at 06:07:30PM +0100, Sven Schreiber wrote: > Well you didn't mentioned why it would be useful for a broad audience, > only that you yourself use it alot. Together with the fact that it's a > one-liner this presumably means that it's not exactly a prime candidate > for adoption. (I'm just another user, so I'm speculating a bit here > based on my reading of past postings on this list.) |