Matrix-matrix multiplication combines two tensors by multiplying rows and columns. In PyTorch, use torch.matmul() or the @ operator; both produce the same result and avoid slow explicit loops. section 8.1.2
Check tensor shapes before multiplying:
- The inner dimensions must match, so incompatible shapes such as (3, 2) @ (3, 2) fail. section 8.1.2
- Transpose a tensor with .T when dimensions need rearranging for multiplication. section 8.1.2
- Use torch.matmul() or @ rather than computing products with for loops. section 8.1.2
Multiplying a tensor by its transpose
tensor_2d.matmul(tensor_2d.T) and tensor_2d @ tensor_2d.T both produce tensor([[14, 32], [32, 77]]) for tensor_2d = [[1, 2, 3], [4, 5, 6]]. section 8.1.2












