[SciPy-user] Cycling the arrays

Yosef Meller yosefmel at post.tau.ac.il
Tue Mar 10 04:09:37 EDT 2009


On Friday 06 March 2009 19:03:10 Marco wrote:
> just a quick question: what is the fastest way to cycle inside an N
> dimensional array?
> I just want to visit each and every element in the N dimensional
> array, then do things.
>
> I can do it with N 'for' cycles, obviously.
> Is there a more compact and maybe faster way to do it?

You can also use ndindex:

for indexes in ndindex(arr.shape):
	print arr[indexes]

there's also ndenumerate that gives you the value as well as the indexes.



More information about the SciPy-User mailing list