PyTorch torch.lcm 函数
torch.lcm 是 PyTorch 中用于计算两个张量元素间最小公倍数(Least Common Multiple)的函数。
函数定义
torch.lcm(input, other, out=None)
参数说明:
input: 第一个输入张量other: 第二个输入张量out: 输出张量
使用示例
实例
import torch
# 创建两个张量
a = torch.tensor([3, 4, 5])
b = torch.tensor([6, 8, 10])
# 计算最小公倍数
y = torch.lcm(a, b)
print(y)
# 创建两个张量
a = torch.tensor([3, 4, 5])
b = torch.tensor([6, 8, 10])
# 计算最小公倍数
y = torch.lcm(a, b)
print(y)
输出结果为:
tensor([ 6, 8, 10])
实例
import torch
# 创建两个张量
a = torch.tensor([12, 15])
b = torch.tensor([18, 25])
# 计算最小公倍数
y = torch.lcm(a, b)
print(y)
# 创建两个张量
a = torch.tensor([12, 15])
b = torch.tensor([18, 25])
# 计算最小公倍数
y = torch.lcm(a, b)
print(y)
输出结果为:
tensor([ 36, 75])

Pytorch torch 参考手册