Here is one way to implement your function:
def f(a, b):
return b - b.multiply(a)
b.multiply(a)- actually an elemental operation and.
Here is an example. aand bare sparse matrices:
In [134]: b.A
Out[134]: array([[False, False, True, True]], dtype=bool)
In [135]: a.A
Out[135]: array([[False, True, False, True]], dtype=bool)
In [136]: f(a,b).A
Out[136]: array([[False, False, True, False]], dtype=bool)
source
share