|
From: Arnd B. <arn...@we...> - 2005-10-10 06:37:39
|
Hi Chris, On Sun, 9 Oct 2005, Chris Barker wrote: > Hi all, > > A freind of mine that I jsut introduced to NumPy asked me about > enumerating an array. What he'd like to see is something like: > > A = N.ones((3,4)) > > for indexes, item in enumeate(A): > print indexes > > result in: > > (0,0) > (0,1) > (0,2) > (1,0) > . > . > . > You get the idea. Can you do this with any of the three NumPys? Not that I know: import Numeric as N A = N.ones((3,4)) for indizes, item in enumerate(A): print indizes,item gives 0 [1 1 1 1] 1 [1 1 1 1] 2 [1 1 1 1] (the same applies for numarrary and the new scipy_core) It might be the best to define your own iterator (e.g. `enumerate_ind`) because the present behaviour can be useful as well. > If not > consider this a feature request for scipy_base. Best, Arnd |