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
x – first input tensor. Should have a boolean data type.
y – second input tensor. Must be compatible with \(x\) (see Broadcasting mechanism and rules ).
- Returns
a tensor containing the result of the element-wise logical XOR operation. The returned tensor must have a data type of
bool
.
See also
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 forF.logical_xor
on boolean tensors.>>> x ^ y Tensor([ True False False], dtype=bool, device=xpux:0)