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

PyTorch torch.linalg.matmul function

PyTorch torch.linalg.matmul function


PyTorch torch reference manual PyTorch torch reference manual

torch.linalg.matmul is a function in PyTorch's linear algebra module used to perform matrix multiplication. It is an torch.matmul alias, providing a more unified linear algebra interface.

Function definition

torch.linalg.matmul(input, other, out=None)

Parameters:

Return Value:


Usage examples

Example

import

torch

Create two matrices

A

=

torch.

randn

(

3

,

4

)

B

=

torch.

randn

(

4

,

5

)

Matrix multiplication

C

=

torch.

linalg

.

matmul

(

A

,

B

)

print

(

"Shape of A:"

,

A.

shape

)

print

(

"Shape of B:"

,

B.

shape

)

print

(

"Shape of C:"

,

C.

shape

)

The output is:

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

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

C 的形状: torch.Size([3, 5])


PyTorch torch reference manual PyTorch torch reference manual