torch.gcd

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

计算inputother的元素-wise最大公约数(GCD)。

计算inputother的逐元素最大公约数(GCD)。

_BOTH_ inputother 都必须是整数类型。

注意

这定义了 $gcd(0, 0) = 0$

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

  • other (Tensor) – 输入的第二个张量

关键字参数

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

示例:

>>> 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])
本页目录