PyTorch torch.vdot Function
Pytorch torch Reference Manual
torch.vdotis a function in PyTorch used to compute the dot product of two vectors (also known as the vector dot product). Unliketorch.dotdifferent,torch.vdotcan handle complex vectors, and automatically multiplies each element of the first vector by the conjugate element of the second vector.
Function Definition
torch.vdot(input, other)
Usage Example
Example
import torch
# Real vector
a = torch.tensor([1, 2, 3])
b = torch.tensor([4, 5, 6])
result = torch.vdot(a, b)
print("vdot result:", result)
# 1*4 + 2*5 + 3*6 = 32
# Complex vector
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)
# Real vector
a = torch.tensor([1, 2, 3])
b = torch.tensor([4, 5, 6])
result = torch.vdot(a, b)
print("vdot result:", result)
# 1*4 + 2*5 + 3*6 = 32
# Complex vector
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 result is:
vdot 结果: tensor(32) 复数 vdot 结果: tensor(70.-6.j)
Other Extensions