The Difference Between torch.matmul() and torch.mul() – PyTorch Tutorial

By | November 23, 2022

In this tutorial, we will introduce the difference between torch.matmul() and torch.mul(), both of them are common used in pytorch script.


torch.matmul() is defined as:

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

It will implement matrix product of two tensors. For example:

Implement Matrix Product Between 3D and 2D Tensor in PyTorch – PyTorch Tutorial

torch.mul() is defined as:

torch.mul(input, other, *, out=None)

It will multiply two tensors. For example: