문제

I am not sure how to multiply two matrices using the XOR addition. For example, here:

>>> b = numpy.array([[1, 0, 0, 0, 1, 1, 0],
                     [0, 1, 0, 0, 0, 1, 1],
                     [0, 0, 1, 0, 1, 1, 1],
                     [0, 0, 0, 1, 1, 0, 1]])
>>> z = numpy.array([1, 1, 0, 1])
>>> z.dot(b)
array([1, 1, 0, 1, 2, 2, 2])

I would like the 4th, 5th, and 6th indices of the resulting array to be computed by:

1(1) xor 0(1) xor 1(0) xor 1(1) = 0
1(1) xor 1(1) xor 1(0) xor 0(1) = 0
0(1) xor 1(1) xor 1(0) xor 1(1) = 0

Any suggestions?

도움이 되었습니까?

해결책

As I commented, you can use z.dot(b) % 2 to get the values you want. This is because chained xors are equivalent to addition mod 2. That is, the result will be 1 if the number of 1s was odd, and 0 if it was even.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top