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

PyTorch torch.mm function

PyTorch torch.mm function


PyTorch torch reference manual PyTorch torch reference manual

torch.mm is a function in PyTorch used to perform two-dimensional matrix multiplication.

Function definition

torch.mm(input, mat2, out)


Usage examples

Example

import

torch

A

=

torch.

randn

(

2

,

3

)

B

=

torch.

randn

(

3

,

4

)

Matrix multiplication

C

=

torch.

mm

(

A

,

B

)

print

(

"A shape:"

,

A.

shape

)

print

(

"B shape:"

,

B.

shape

)

print

(

"C shape:"

,

C.

shape

)

The output is:

A 形状: torch.Size([2, 3])

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

C 形状: torch.Size([2, 4])


PyTorch torch reference manual PyTorch torch reference manual