paddle. logical_xor ( x, y, out=None, name=None ) [source]

logical_xor operator computes element-wise logical XOR on x and y, and returns out. x, y and out are N-dim boolean Tensor. Each element of out is calculated by

\[out = (x || y) \&\& !(x \&\& y)\]


paddle.logical_xor supports broadcasting. If you want know more about broadcasting, please refer to Broadcasting.

  • x (Tensor) – the input tensor, it’s data type should be bool.

  • y (Tensor) – the input tensor, it’s data type should be bool.

  • out (Tensor) – The Tensor that specifies the output of the operator, which can be any Tensor that has been created in the program. The default value is None, and a new Tensor will be created to save the output.

  • name (str, optional) – Name for the operation (optional, default is None). For more information, please refer to Name.


N-D Tensor. A location into which the result is stored. It’s dimension equals with x.


import paddle
import numpy as np

x_data = np.array([True, False], dtype=np.bool).reshape([2, 1])
y_data = np.array([True, False, True, False], dtype=np.bool).reshape([2, 2])
x = paddle.to_tensor(x_data)
y = paddle.to_tensor(y_data)
res = paddle.logical_xor(x, y)
print(res) # [[False,  True], [ True, False]]