torch.add(input, other, *, out=None)

Adds the scalar other to each element of the input input and returns a new resulting tensor.

$\text{out} = \text{input} + \text{other}$

If input is of type FloatTensor or DoubleTensor, other must be a real number, otherwise it should be an integer.

Parameters
• input (Tensor) – the input tensor.

• value (Number) – the number to be added to each element of input

Keyword Arguments

out (Tensor, optional) – the output tensor.

Example:

>>> a = torch.randn(4)
>>> a
tensor([ 0.0202,  1.0985,  1.3506, -0.6056])
tensor([ 20.0202,  21.0985,  21.3506,  19.3944])

torch.add(input, other, *, alpha=1, out=None)

Each element of the tensor other is multiplied by the scalar alpha and added to each element of the tensor input. The resulting tensor is returned.

The shapes of input and other must be broadcastable.

$\text{out} = \text{input} + \text{alpha} \times \text{other}$

If other is of type FloatTensor or DoubleTensor, alpha must be a real number, otherwise it should be an integer.

Parameters
• input (Tensor) – the first input tensor

• other (Tensor) – the second input tensor

Keyword Arguments
• alpha (Number) – the scalar multiplier for other

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

Example:

>>> a = torch.randn(4)
>>> a
tensor([-0.9732, -0.3497,  0.6245,  0.4022])
>>> b = torch.randn(4, 1)
>>> b
tensor([[ 0.3743],
[-1.7724],
[-0.5811],
[-0.8017]])