Reputation: 151
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?
Upvotes: 3
Views: 4910
Reputation: 104792
As I commented, you can use z.dot(b) % 2
to get the values you want. This is because chained xor
s are equivalent to addition mod 2. That is, the result will be 1
if the number of 1
s was odd, and 0
if it was even.
Upvotes: 6