捷徑

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

文件

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources