Rate this Page

torch.lerp#

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

Does a linear interpolation of two tensorsstart (given byinput) andend basedon a scalar or tensorweight and returns the resultingout tensor.

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

The shapes ofstart andend must bebroadcastable. Ifweight is a tensor, thenthe shapes ofweight,start, andend must bebroadcastable.

Parameters
  • input (Tensor) – the tensor with the starting points

  • end (Tensor) – the tensor with the ending points

  • weight (float ortensor) – the weight for the interpolation formula

Keyword Arguments

out (Tensor,optional) – the output tensor.

Example:

>>>start=torch.arange(1.,5.)>>>end=torch.empty(4).fill_(10)>>>starttensor([ 1.,  2.,  3.,  4.])>>>endtensor([ 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])