torch.logical_xor

torch.logical_xor(input, other, *, out=None) Tensor

计算给定输入张量的逐元素逻辑异或(XOR)操作。将零值视为False,非零值视为True

参数
  • input (Tensor) – 需要输入的张量。

  • other (Tensor) – 与之计算异或运算的张量

关键字参数

out (Tensor, 可选) – 指定输出张量。

示例:

>>> torch.logical_xor(torch.tensor([True, False, True]), torch.tensor([True, False, False]))
tensor([False, False,  True])
>>> a = torch.tensor([0, 1, 10, 0], dtype=torch.int8)
>>> b = torch.tensor([4, 0, 1, 0], dtype=torch.int8)
>>> torch.logical_xor(a, b)
tensor([ True,  True, False, False])
>>> torch.logical_xor(a.double(), b.double())
tensor([ True,  True, False, False])
>>> torch.logical_xor(a.double(), b)
tensor([ True,  True, False, False])
>>> torch.logical_xor(a, b, out=torch.empty(4, dtype=torch.bool))
tensor([ True,  True, False, False])
本页目录