[Numpy-discussion] Can you enumerarte an array?

Chris Barker Chris.Barker at noaa.gov
Mon Oct 10 11:37:55 EDT 2005

Travis Oliphant wrote:
> All flavors of Numeric would return
> 0  a[0]
> 1  a[1]
> .
> .
> .
> n-1  a[n-1]
> where n=a.shape[0]
> in response to index, item in enumerate(A):

Right, as expected, and as Anrd pointed out, this is useful behaviour.

> In scipy you could also get
> 0 a.flat[0]
> 1 a.flat[1]

I do like the new flat!

> To do something like he wants, I think we would have to construct a 
> different iterator then enumerate.

Exactly,. I didn't mean to imply that that's what the built-in enumerate 
should do.

> It wouldn't be that hard using the 
> a.flat iterator (it's just a remapping of the 1-d index).

Cool. then again, consider this a feature request, for a nd_enumerate, 
or whatever you want to call it.

I'm sorry that implimenting something like this myself is way out my depth!


More information about the NumPy-Discussion mailing list