tf.math.logical_xor
Stay organized with collections
Save and categorize content based on your preferences.
Logical XOR function.
tf.math.logical_xor(
x, y, name='LogicalXor'
)
x ^ y = (x | y) & ~(x & y)
Requires that x
and y
have the same shape or have
broadcast-compatible
shapes. For example, x
and y
can be:
- Two single elements of type
bool
- One
tf.Tensor
of type bool
and one single bool
, where the result will
be calculated by applying logical XOR with the single element to each
element in the larger Tensor.
- Two
tf.Tensor
objects of type bool
of the same shape. In this case,
the result will be the element-wise logical XOR of the two input tensors.
Usage:
a = tf.constant([True])
b = tf.constant([False])
tf.math.logical_xor(a, b)
<tf.Tensor: shape=(1,), dtype=bool, numpy=array([ True])>
c = tf.constant([True])
x = tf.constant([False, True, True, False])
tf.math.logical_xor(c, x)
<tf.Tensor: shape=(4,), dtype=bool, numpy=array([ True, False, False, True])>
y = tf.constant([False, False, True, True])
z = tf.constant([False, True, False, True])
tf.math.logical_xor(y, z)
<tf.Tensor: shape=(4,), dtype=bool, numpy=array([False, True, True, False])>
Args |
x
|
A tf.Tensor type bool.
|
y
|
A tf.Tensor of type bool.
|
name
|
A name for the operation (optional).
|
Returns |
A tf.Tensor of type bool with the same size as that of x or y.
|
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 2024-04-26 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 2024-04-26 UTC."],[],[],null,["# tf.math.logical_xor\n\n\u003cbr /\u003e\n\n|------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/ops/math_ops.py#L1708-L1757) |\n\nLogical XOR function.\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.logical_xor`](https://www.tensorflow.org/api_docs/python/tf/math/logical_xor), [`tf.compat.v1.math.logical_xor`](https://www.tensorflow.org/api_docs/python/tf/math/logical_xor)\n\n\u003cbr /\u003e\n\n tf.math.logical_xor(\n x, y, name='LogicalXor'\n )\n\nx \\^ y = (x \\| y) \\& \\~(x \\& y)\n\nRequires that `x` and `y` have the same shape or have\n[broadcast-compatible](http://docs.scipy.org/doc/numpy/user/basics.broadcasting.html)\nshapes. For example, `x` and `y` can be:\n\n- Two single elements of type `bool`\n- One [`tf.Tensor`](../../tf/Tensor) of type `bool` and one single `bool`, where the result will be calculated by applying logical XOR with the single element to each element in the larger Tensor.\n- Two [`tf.Tensor`](../../tf/Tensor) objects of type `bool` of the same shape. In this case, the result will be the element-wise logical XOR of the two input tensors.\n\n#### Usage:\n\n a = tf.constant([True])\n b = tf.constant([False])\n tf.math.logical_xor(a, b)\n \u003ctf.Tensor: shape=(1,), dtype=bool, numpy=array([ True])\u003e\n\n c = tf.constant([True])\n x = tf.constant([False, True, True, False])\n tf.math.logical_xor(c, x)\n \u003ctf.Tensor: shape=(4,), dtype=bool, numpy=array([ True, False, False, True])\u003e\n\n y = tf.constant([False, False, True, True])\n z = tf.constant([False, True, False, True])\n tf.math.logical_xor(y, z)\n \u003ctf.Tensor: shape=(4,), dtype=bool, numpy=array([False, True, True, False])\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|--------|------------------------------------------------|\n| `x` | A [`tf.Tensor`](../../tf/Tensor) type bool. |\n| `y` | A [`tf.Tensor`](../../tf/Tensor) of type bool. |\n| `name` | A name for the operation (optional). |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A [`tf.Tensor`](../../tf/Tensor) of type bool with the same size as that of x or y. ||\n\n\u003cbr /\u003e"]]