我想要的:
迭代1:
[[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]]
[[1, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]]
[[1, 1, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]]
iterate -1(最后一次迭代):
[[1, 1, 1, 1],
[1, 1, 1, 1],
[1, 1, 1, 1],
[1, 1, 1, 1]]
我是这样想的:
import itertools
n = 2
list_of_solution = []
for i in itertools.product([0, 1], repeat=n*n):
sol= [list(i)[x:x+n] for x in range(0, len(list(i)), n)]
list_of_solution.append(sol)
print(list_of_solution)
结果
[[[0, 0], [0, 0]],
[[0, 0], [0, 1]],
[[0, 0], [1, 0]],
...
[[1, 1], [1, 1]]]