Is there function to get an iterator over an arbitrary dimension of a numpy array?
Iterating over the first dimension is easy...
In [63]: c = numpy.a
I'd use the following:
c = numpy.arange(2 * 3 * 4) c.shape = (2, 3, 4) for r in numpy.rollaxis(c, 2): print(r)
The function rollaxis creates a new view on the array. In this case it's moving axis 2 to the front, equivalent to the operation c.transpose(2, 0, 1).
c.transpose(2, 0, 1)