Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PyTorch torch.outer function

PyTorch torch.outer function


PyTorch torch reference manual 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

)

print

(

result

)

The output is:

tensor([[ 4,  5,  6],

        [ 8, 10, 12],

        [12, 15, 18]])


PyTorch torch reference manual PyTorch torch reference manual