You can create such a list easily with pure python:
from itertools import product
list(product(range(my_matrix.shape[0]), range(my_matrix.shape[1])))
Result is
[(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2)]
If you are not using the explicit list but only want to iterate over the indices, leave the list(...)
away. This will save memory and computation time, as the indices will be generated when they are used only.
However, if you want to use the result to index a numpy array, it may be more convenient to use np.ix_
:
np.ix_(np.arange(my_matrix.shape[0]), np.arange(my_matrix.shape[1]))
Output is
(array([[0],
[1]]), array([[0, 1, 2]]))