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) – 輸入張量。 other (Tensor 或 Number) – 從 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])