torch.sub — PyTorch 2.5 documentation (original) (raw)

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

Subtracts other, scaled by alpha, from input.

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

Supports broadcasting to a common shape,type promotion, and integer, float, and complex inputs.

Parameters

Keyword Arguments

Example:

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