PyTorch torch.linalg.matmul function
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:
input(Tensor): the first input tensor.other(Tensor): The second input tensor.out(Tensor, optional): the output tensor.
Return Value:
torch.Tensor: Returns the result of matrix multiplication.
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
)
(
"Shape of A:"
,
A.
shape
)
(
"Shape of B:"
,
B.
shape
)
(
"Shape of C:"
,
C.
shape
)
The output is:
A 的形状: torch.Size([3, 4])
B 的形状: torch.Size([4, 5])
C 的形状: torch.Size([3, 5])