PyTorch torch.outer Function
Pytorch torch Reference Manual
torch.outeris a function in PyTorch used to compute the outer product (also called cross product or tensor product) of two vectors. The outer product multiplies each element in one vector with all elements in the other vector to generate a matrix.
Function Definition
torch.outer(vec1, vec2, out)
Usage Example
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)
print(result)
# Define two vectors
vec1 = torch.tensor([1, 2, 3])
vec2 = torch.tensor([4, 5, 6])
# Compute the outer product
result = torch.outer(vec1, vec2)
print(result)
The output result is:
tensor([[ 4, 5, 6],
[ 8, 10, 12],
[12, 15, 18]])
Other Extensions