Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Binary Matrix Multiplication with OR Instead of Sum

I am trying to determine how to perform binary matrix multiplication in Python / Numpy / Scipy where instead of plus (addition), OR is used, meaning when we "multiply" the two matrices below

1  0
1  1
0  1

1  1  0
0  1  1

we should get

[[1., 1., 0],
[1., 1., 1.],
[0, 1., 1.]]

Any ideas?

like image 504
BBSysDyn Avatar asked Oct 13 '25 05:10

BBSysDyn


1 Answers

> a = np.matrix([[1,1,0],[0,1,1]], dtype=bool)
> a.T * a 
matrix([[ True,  True, False],
        [ True,  True,  True],
        [False,  True,  True]], dtype=bool)

Normal numpy arrays have access to matrix-style multiplication via the dot function.

like image 58
U2EF1 Avatar answered Oct 14 '25 20:10

U2EF1