numpy.ndenumerate to return indices in Fortran order? numpy.ndenumerate to return indices in Fortran order? numpy numpy

numpy.ndenumerate to return indices in Fortran order?


You can do it with np.nditer as follows:

it = np.nditer(a, flags=['multi_index'], order='F')while not it.finished:    print it.multi_index, it[0]    it.iternext()

np.nditer is a very powerful beast that exposes some of the internal C iterator in Python, take a look at Iterating Over Arrays in the docs.


Just taking a transpose would give you what you want:

a = np.array([[11, 12],              [21, 22],              [31, 32]])for (i,j),v in np.ndenumerate(a.T):    print j, i, v

Result:

0 0 111 0 212 0 310 1 121 1 222 1 32