سؤال

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?

هل كانت مفيدة؟

المحلول

As per flebool's comment the solution is to use for idx in np.ndindex(foo.shape):

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top