PyTorch torch.outer function
PyTorch torch reference manual
torch.outer is a function in PyTorch used to compute the outer product of two vectors (also called the cross product or tensor product). The outer product multiplies each element of one vector by all elements of the other, producing a matrix.
Function definition
torch.outer(vec1, vec2, out)
Usage examples
Example
import
torch
Define two vectors
vec1
=
torch.
tensor
(
[
1
,
2
,
3
]
)
vec2
=
torch.
tensor
(
[
4
,
5
,
6
]
)
Compute the outer product
result
=
torch.
outer
(
vec1
,
vec2
)
(
result
)
The output is:
tensor([[ 4, 5, 6],
[ 8, 10, 12],
[12, 15, 18]])