Rate this Page

torch.sub#

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

Subtractsother, scaled byalpha, frominput.

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

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

Parameters
  • input (Tensor) – the input tensor.

  • other (Tensor orNumber) – the tensor or number to subtract frominput.

Keyword Arguments
  • alpha (Number) – the multiplier forother.

  • out (Tensor,optional) – the output tensor.

Example:

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