tf.keras.ops.isin
Stay organized with collections
Save and categorize content based on your preferences.
Test whether each element of x1 is present in x2.
tf.keras.ops.isin(
x1, x2, assume_unique=False, invert=False
)
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.
Args |
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.
|
Returns |
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])
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2026-10-31 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2026-10-31 UTC."],[],[]]