Matrix Multiplication with Bitwise Operators

I want to create a bitmask vector that masks values ​​that exceed a given value. Something like [1, 2, 3, 4, 5] * [> 3,> 3,> 3,> 3,> 3] = [0, 0, 0, 1, 1]. I want to be able to run this on anano in order to get a faster calculation time for matrix operations. Is there a linear algebra procedure that can be written using bitwise operators or bits to create this bitmask? I'm currently looking at this matrix, and I would like to move the calculation to a GPU using theano, which requires more matrix multiplication. Thanks for any help.

+4
source share
1 answer

You can get exactly what you want, with logical operations between matrices. for instance

print((np.r_[1, 2, 3, 4, 5] > 3))

will give

[False False False  True  True]

And if you want integers, you can do

print((np.r_[1, 2, 3, 4, 5] > 3).astype(int) )

and get

[0 0 0 1 1]
+2
source

Source: https://habr.com/ru/post/1666796/


All Articles