Находит все комбинации строк со значением xor
, что приводит к нулю (False
).
Для поиска всех комбинаций строк используйте itertools.combinations
.
import numpy as np
from itertools import combinations
A = np.array([[0,1,0,1,0],
[0,1,0,0,0],
[0,0,1,1,0],
[0,0,1,0,0],
[0,0,1,0,0]])
print('All combinations of rows with xor resulting in zero: ')
for i in range(1, len(A)+1):
for x in combinations(A, i):
if not np.logical_xor.reduce(x).any():
print(x)
# All combinations of rows with xor resulting in zero:
# (array([0, 0, 1, 0, 0]), array([0, 0, 1, 0, 0]))
# (array([0, 1, 0, 1, 0]), array([0, 1, 0, 0, 0]), array([0, 0, 1, 1, 0]), array([0, 0, 1, 0, 0]))
# (array([0, 1, 0, 1, 0]), array([0, 1, 0, 0, 0]), array([0, 0, 1, 1, 0]), array([0, 0, 1, 0, 0]))