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

PyTorch torch.vdot function

PyTorch torch.vdot function


PyTorch torch reference manual PyTorch torch reference manual

torch.vdot A function in PyTorch for computing the dot product of two vectors (also called the vector dot product). Unlike a plain dot product, torch.dot in Vue 2,torch.vdot it handles complex vectors and automatically multiplies each element of the first vector by the conjugate of the corresponding element in the second vector.

Function definition

torch.vdot(input, other)


Usage examples

Example

import

torch

Real-valued vectors

a

=

torch.

tensor

(

[

1

,

2

,

3

]

)

b

=

torch.

tensor

(

[

4

,

5

,

6

]

)

result

=

torch.

vdot

(

a

,

b

)

print

(

"vdot result:"

,

result

)

14 + 25 + 3*6 = 32

Complex vectors

c

=

torch.

tensor

(

[

1

+2j

,

3

+4j

]

)

d

=

torch.

tensor

(

[

5

+6j

,

7

+8j

]

)

result_complex

=

torch.

vdot

(

c

,

d

)

print

(

"Complex vdot result:"

,

result_complex

)

The output is:

vdot 结果: tensor(32)

复数 vdot 结果: tensor(70.-6.j)


PyTorch torch reference manual PyTorch torch reference manual