捷徑

torch.lerp

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

根據純量或張量 weight 對兩個張量 start (由 input 給定) 和 end 進行線性插值,並傳回產生的 out 張量。

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

startend 的形狀必須是 可廣播的 (broadcastable)。 如果 weight 是一個張量,則 weightstartend 的形狀必須是 可廣播的 (broadcastable)

參數
  • input (Tensor) – 具有起點的張量。

  • end (Tensor) – 具有終點的張量。

  • weight (floattensor (張量)) – 插值公式的權重。

關鍵字參數

out (Tensor, optional (可選)) – 輸出張量。

範例

>>> 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])

文件

存取 PyTorch 的完整開發者文件

檢視文件

教學課程

取得初學者和進階開發人員的深入教學課程

檢視教學課程

資源

尋找開發資源並獲得您問題的解答

檢視資源