Add
add(input, other, out=NULL)
Adds the scalar other
to each element of the input input
and returns a new resulting tensor.
input
is of type FloatTensor or DoubleTensor, other
must be
a real number, otherwise it should be an integer.
add(input, other, *, alpha=1, out=NULL)
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 .
other
is of type FloatTensor or DoubleTensor, alpha
must be
a real number, otherwise it should be an integer.
Examples
if (torch_is_installed()) {
a = torch_randn(c(4))
a
torch_add(a, 20)
a = torch_randn(c(4))
a
b = torch_randn(c(4, 1))
b
torch_add(a, b)
}
#> torch_tensor
#> -3.2509 -3.2558 -2.8322 -1.5658
#> -1.1021 -1.1069 -0.6833 0.5831
#> -2.2858 -2.2906 -1.8670 -0.6006
#> -0.4795 -0.4844 -0.0608 1.2056
#> [ CPUFloatType{4,4} ]