PyTorch torch.lcm Function


Pytorch torch 参考手册Pytorch torch Reference Manual

torch.lcmis a function in PyTorch used to calculate the Least Common Multiple (LCM) between elements of two tensors.

Function Definition

torch.lcm(input, other, out=None)

Parameter description:

  • input: The first input tensor
  • other: The second input tensor
  • out: The output tensor

Usage Example

Example

import torch

# Create two tensors
a = torch.tensor([3, 4, 5])
b = torch.tensor([6, 8, 10])

# Calculate the least common multiple
y = torch.lcm(a, b)
print(y)

The output result is:

tensor([ 6,  8, 10])

Example

import torch

# Create two tensors
a = torch.tensor([12, 15])
b = torch.tensor([18, 25])

# Calculate the least common multiple
y = torch.lcm(a, b)
print(y)

The output result is:

tensor([ 36,  75])

Pytorch torch 参考手册Pytorch torch Reference Manual

Other Extensions