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

PyTorch torch.addmv Function

PyTorch torch.addmv Function


PyTorch torch reference manual PyTorch torch reference manual

torch.addmv is a function in PyTorch used to add the result of matrix-vector multiplication to an input vector. It performs the multiplication of a matrix and a vector, then adds the result to input.

Function definition

torch.addmv(input, mat, vec, *, beta=1.0, alpha=1.0, out=None)

Parameters:

Return Value:


Usage examples

Example

import

torch

Create the input vector, the matrix, and the vector

input

=

torch.

randn

(

3

)

mat

=

torch.

randn

(

3

,

4

)

vec

=

torch.

randn

(

4

)

Perform addmv

result

=

torch.

addmv

(

input

,

mat

,

vec

)

print

(

"Input vector shape:"

,

input

.

shape

)

print

(

"Matrix shape:"

,

mat.

shape

)

print

(

"Vector shape:"

,

vec.

shape

)

print

(

"Result shape:"

,

result.

shape

)

print

(

result

)

The output is:

输入向量形状: torch.Size([3])

矩阵形状: torch.Size([3, 4])

向量形状: torch.Size([4])

结果形状: torch.Size([3])

tensor([-1.0182, -0.4901, -0.9490])


PyTorch torch reference manual PyTorch torch reference manual