評價此頁

torch.gcd#

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

計算 inputother 的逐元素最大公約數 (GCD)。

inputother 都必須是整數型別。

注意

這定義了 gcd(0,0)=0gcd(0, 0) = 0

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

  • other (Tensor) – 第二個輸入張量

關鍵字引數

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

示例

>>> a = torch.tensor([5, 10, 15])
>>> b = torch.tensor([3, 4, 5])
>>> torch.gcd(a, b)
tensor([1, 2, 5])
>>> c = torch.tensor([3])
>>> torch.gcd(a, c)
tensor([1, 1, 3])