PyTorch torch.lcm Function
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 tensorother: The second input tensorout: 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)
# 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)
# 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])
Other Extensions