How do I compute the set difference of elements of two arrays in tensorflow?
Example: I want to subtract all elements of b
from a
:
import numpy as np
a = np.array([[1, 0, 1], [2, 0, 1], [3, 0, 1], [0, 0, 0]])
b = np.array([[1, 0, 1], [2, 0, 1]])
Expected result:
array([[3, 0, 1],
[0, 0, 0]])
It can probably be done with tf.sets.set_difference()
, but I fail to see how.
In numpy, you can do something like this, but I'm after a tensorflow solution to offload this operation to a GPU device, as this operation is computationally expensive for large arrays.