torch.sub¶ torch.sub(input, other, *, alpha=1, out=None) → Tensor¶ 從 input 中減去 other,並按 alpha 進行縮放。 outi=inputi−alpha×otheri\text{{out}}_i = \text{{input}}_i - \text{{alpha}} \times \text{{other}}_i outi=inputi−alpha×otheri支援廣播到通用形狀、型別提升以及整數、浮點數和複數輸入。 引數 input (Tensor) – 輸入 tensor。 other (Tensor 或 Number) – 從 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])