Domanda

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?

È stato utile?

Soluzione

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top