PyTorch torch.linalg.matmul Function


Pytorch torch 参考手册Pytorch torch Reference Manual

torch.linalg.matmulis a function in PyTorch's linear algebra module used to perform matrix multiplication. It istorch.matmulan alias that provides 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 Example

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 result is:

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

Pytorch torch 参考手册Pytorch torch Reference Manual

Other Extensions