我有这个:
shape = (2, 4) # arbitrary, could be 3 dimensions such as (3, 5, 7), etc...
for i in itertools.product(*(range(x) for x in shape)):
print(i)
# output: (0, 0) (0, 1) (0, 2) (0, 3) (1, 0) (1, 1) (1, 2) (1, 3)
Run Code Online (Sandbox Code Playgroud)
到目前为止,非常好,itertools.product在每次迭代中推进最右边的元素.但现在我希望能够根据以下内容指定迭代顺序:
axes = (0, 1) # normal order
# output: (0, 0) (0, 1) (0, 2) (0, 3) (1, 0) (1, 1) (1, 2) (1, 3)
axes = (1, 0) # reversed order
# …Run Code Online (Sandbox Code Playgroud)