[Numpy-discussion] Can you enumerarte an array?
arnd.baecker at web.de
Sun Oct 9 23:39:01 EDT 2005
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:
> 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
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.
More information about the NumPy-Discussion