lcm

paddle. lcm ( x, y, name=None ) [源代码]

计算两个输入的按元素绝对值的最小公倍数,输入必须是整型。

注解

lcm(0,0)=0, lcm(0, y)=0

如果x和y的shape不一致,会对两个shape进行广播操作,得到一致的shape(并作为输出结果的shape), 请参见 cn_user_guide_broadcasting

参数

  • x (Tensor) - 输入的Tensor,数据类型为:int32,int64。

  • y (Tensor) - 输入的Tensor,数据类型为:int32,int64。

  • name (str,可选) - 操作的名称(可选,默认值为None)。更多信息请参见 Name

返回

输出Tensor,与输入数据类型相同。

代码示例

import paddle

x1 = paddle.to_tensor(12)
x2 = paddle.to_tensor(20)
paddle.lcm(x1, x2)
# Tensor(shape=[1], dtype=int64, place=CUDAPlace(0), stop_gradient=True,
#        [60])

x3 = paddle.arange(6)
paddle.lcm(x3, x2)
# Tensor(shape=[6], dtype=int64, place=CUDAPlace(0), stop_gradient=True,
#        [0, 20, 20, 60, 20, 20])

x4 = paddle.to_tensor(0)
paddle.lcm(x4, x2)
# Tensor(shape=[1], dtype=int64, place=CUDAPlace(0), stop_gradient=True,
#        [0])

paddle.lcm(x4, x4)
# Tensor(shape=[1], dtype=int64, place=CUDAPlace(0), stop_gradient=True,
#        [0])

x5 = paddle.to_tensor(-20)
paddle.lcm(x1, x5)
# Tensor(shape=[1], dtype=int64, place=CUDAPlace(0), stop_gradient=True,
#        [60])