As per flebool's comment the solution is to use for idx in np.ndindex(foo.shape):
Numpy Index Iterator
Question
I don't remember whether this is Python or numpy specific. I once found an index iterator that is not in the main introduction and however I try to look for it, I couldn't find it anymore. This is what it gave me:
>>> foo = ones((1,2,3))
>>> for i in foo.getThisMagicIteratorIndexThiny():
>>> print i
(0,0,0)
(0,0,1)
(0,0,2)
(0,1,0)
And, foo[i]
would return the corresponding value. Does anyone know which iterator I am talking about?
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow