lerp
基于给定的 weight 计算 x 与 y 的线性插值
\[lerp(x, y, weight) = x + weight * (y - x)\]
参数
x (Tensor) - 输入的 Tensor,作为线性插值开始的点,数据类型为:bfloat16、float16、float32、float64。别名
input。y (Tensor) - 输入的 Tensor,作为线性插值结束的点,数据类型为:bfloat16、float16、float32、float64。别名
end。weight (float|Tensor) - 给定的权重值,weight 为 Tensor 时数据类型为:bfloat16、float16、float32、float64。
name (str,可选) - 操作的名称(可选,默认值为 None)。更多信息请参见 api_guide_Name。
关键字参数
out (Tensor,可选) - 输出 Tensor,若不为
None,计算结果将保存在该 Tensor 中,默认值为None。
返回
输出 Tensor,与 x 数据类型相同。
代码示例
>>> import paddle
>>> x = paddle.arange(1.0, 5.0, dtype='float32')
>>> y = paddle.empty([4], dtype='float32')
>>> y.fill_(10.0)
>>> out = paddle.lerp(x, y, 0.5)
>>> out
Tensor(shape=[4], dtype=float32, place=Place(cpu), stop_gradient=True,
[5.50000000, 6. , 6.50000000, 7. ])
>>> # Using out parameter
>>> result = paddle.empty([4], dtype='float32')
>>> paddle.lerp(x, y, 0.5, out=result)
>>> result
Tensor(shape=[4], dtype=float32, place=Place(cpu), stop_gradient=True,
[5.50000000, 6. , 6.50000000, 7. ])
>>> # Using parameter aliases (input for x, end for y)
>>> out = paddle.lerp(input=x, end=y, weight=0.5)
>>> out
Tensor(shape=[4], dtype=float32, place=Place(cpu), stop_gradient=True,
[5.50000000, 6. , 6.50000000, 7. ])