快捷方式

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) – 輸入 tensor。

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

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

  • out (Tensor可選) – 輸出 tensor。

示例

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

文件

查閱 PyTorch 的全面開發者文件

檢視文件

教程

獲取適合初學者和高階開發者的深入教程

檢視教程

資源

查詢開發資源並獲得問題解答

檢視資源