megengine.functional.logical_xor#

logical_xor(x, y)[source]#

Element-wise logical XOR.

Computes the logical XOR for each element \(x_i\) of the input tensor \(x\) with the respective element \(y_i\) of the input tensor \(y\).

Parameters:
Returns:

a tensor containing the result of the element-wise logical XOR operation. The returned tensor must have a data type of bool.

Examples

>>> F.logical_xor(True, False)
Tensor(True, dtype=bool, device=xpux:0)

Element-wise logical XOR:

>>> x = Tensor([True, False, True])
>>> y = Tensor([False, False, True])
>>> F.logical_xor(x, y)
Tensor([ True False False], dtype=bool, device=xpux:0)

The ^ operator can be used as a shorthand for F.logical_xor on boolean tensors.

>>> x ^ y
Tensor([ True False False], dtype=bool, device=xpux:0)