In Python, I want to multiply a binary matrix (each element is 0 or 1) with a binary vector. The size of the matrix is something like 100000 x 100 and the vector has 100 elements. If V and x are respectively the matrix and the vector (initialized as bool), this simple code can do the job:
V.astype(np.int8).dot(x.astype(np.int8))
My question is: is there a way to do it faster by taking advantage of the very binary nature of the 2 operands? After all, each of the 100000 operations is the sum of the logical AND between one row of V and the vector x.
Thank you for any help. Patrick
EDIT: Just tried your solution unutbu. Strangely enough, the performance for the 2 methods (int8 et einsum) seems to be similar on my machine.