tf.keras.ops.isin

Test whether each element of x1 is present in x2.

This operation performs element-wise checks to determine if each value in x1 is contained within x2. The result is a boolean tensor with the same shape as x1, where each entry is True if the corresponding element in x1 is in x2, and False otherwise.

x1 Input tensor or array-like structure to test.
x2 Values against which each element of x1 is tested. Can be a tensor, list, or scalar.
assume_unique Boolean (default: False). If True, assumes both x1 and x2 contain only unique elements. This can speed up the computation. If False, duplicates will be handled correctly but may impact performance.
invert A boolean (default: False). If True, inverts the result. Entries will be True where x1 elements are not in x2.

A boolean tensor of the same shape as x1 indicating element-wise membership in x2.

Example:

from keras import ops
x1 = ops.array([0, 1, 2, 5])
x2 = ops.array([0, 2])
result = ops.isin(x1, x2)
array([ True, False,  True, False])