Shortcuts

torch.lerp

torch.lerp(input, end, weight, *, out=None)

对两个张量 start(由 input 给出)和 end 进行线性插值,基于标量或张量 weight,并返回结果张量 out

outi=starti+weighti×(endistarti)\text{out}_i = \text{start}_i + \text{weight}_i \times (\text{end}_i - \text{start}_i)

startend 的形状必须 可广播。如果 weight 是一个张量,那么 weightstartend 的形状必须 可广播

Parameters
  • 输入 (Tensor) – 包含起点的张量

  • 结束 (Tensor) – 包含结束点的张量

  • 权重 (浮点数张量) – 插值公式的权重

Keyword Arguments

输出 (张量, 可选) – 输出张量。

示例:

>>> start = torch.arange(1., 5.)
>>> end = torch.empty(4).fill_(10)
>>> start
tensor([ 1.,  2.,  3.,  4.])
>>> end
tensor([ 10.,  10.,  10.,  10.])
>>> torch.lerp(start, end, 0.5)
tensor([ 5.5000,  6.0000,  6.5000,  7.0000])
>>> torch.lerp(start, end, torch.full_like(start, 0.5))
tensor([ 5.5000,  6.0000,  6.5000,  7.0000])
优云智算