On this page
torch.addr
torch.addr(input, vec1, vec2, *, beta=1, alpha=1, out=None) → Tensor-
Performs the outer-product of vectors
vec1andvec2and adds it to the matrixinput.Optional values
betaandalphaare scaling factors on the outer product betweenvec1andvec2and the added matrixinputrespectively.If
betais 0, theninputwill be ignored, andnanandinfin it will not be propagated.If
vec1is a vector of sizenandvec2is a vector of sizem, theninputmust be broadcastable with a matrix of size andoutwill be a matrix of size .- Parameters
- Keyword Arguments
-
- beta (Number, optional) – multiplier for
input( ) - alpha (Number, optional) – multiplier for ( )
- out (Tensor, optional) – the output tensor.
- beta (Number, optional) – multiplier for
Example:
>>> vec1 = torch.arange(1., 4.) >>> vec2 = torch.arange(1., 3.) >>> M = torch.zeros(3, 2) >>> torch.addr(M, vec1, vec2) tensor([[ 1., 2.], [ 2., 4.], [ 3., 6.]])
© 2024, PyTorch Contributors
PyTorch has a BSD-style license, as found in the LICENSE file.
https://pytorch.org/docs/2.1/generated/torch.addr.html