評價此頁

torch.logical_xor#

torch.logical_xor(input: Tensor, other: Tensor, *, out: Optional[Tensor]) Tensor#

計算給定輸入張量的逐元素邏輯異或。零被視為 False,非零被視為 True

引數
  • input (Tensor) – 輸入張量。

  • other (Tensor) – 用於計算異或的張量

關鍵字引數

out (Tensor, optional) – 輸出張量。

示例

>>> 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])