Matrix Multiplicaton by Tensor.Matmul

How we can multiply matrix by using tensor.matmul
Anybody help me in this logic and why we need this

Hi @hamzach1288 :slightly_smiling_face:

matmul function is used to perform matrix multiplication of two tensors.

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

  • input – the first tensor to be multiplied
  • other – the second tensor to be multiplied

Returns: out – the output tensor.


tensor1 = torch.randn(10, 3, 4)
tensor2 = torch.randn(4, 5)

torch.matmul(tensor1, tensor2).size()

Output: torch.Size([10, 3, 5])

For reference, check this link