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

PyTorch torch.ger function

PyTorch torch.ger function


PyTorch torch reference manual PyTorch torch reference manual

torch.ger A function in PyTorch for computing the outer product (Gram matrix) of two vectors.

Function definition

torch.ger(input, vec2, out=None)


Usage examples

Example

import

torch

Create two vectors

vec1

=

torch.

tensor

(

[

1

,

2

,

3

]

)

vec2

=

torch.

tensor

(

[

4

,

5

,

6

]

)

Compute the outer product

result

=

torch.

ger

(

vec1

,

vec2

)

print

(

"Outer product result:"

)

print

(

result

)

The output is:

tensor([[ 4,  5,  6],

        [ 8, 10, 12],

        [12, 15, 18]])


PyTorch torch reference manual PyTorch torch reference manual