捷徑

torch.sub

torch.sub(input, other, *, alpha=1, out=None) Tensor

input 中減去 other,並依 alpha 縮放。

outi=inputialpha×otheri\text{{out}}_i = \text{{input}}_i - \text{{alpha}} \times \text{{other}}_i

支援廣播到通用形狀型別提升,以及整數、浮點數和複數輸入。

參數
  • input (Tensor) – 輸入張量。

  • other (TensorNumber) – 從 input 中減去的張量或數字。

關鍵字參數
  • alpha (Number) – other 的乘數。

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

範例

>>> a = torch.tensor((1, 2))
>>> b = torch.tensor((0, 1))
>>> torch.sub(a, b, alpha=2)
tensor([1, 0])

文件

存取 PyTorch 的完整開發者文件

檢視文件

教學課程

取得針對初學者和高級開發人員的深入教學課程

檢視教學課程

資源

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

檢視資源