经常会在编程中遇到理解矩阵行和列的事情。 1、要明确无论这个张量有多少维度,它的矩阵乘法都只能作用于最后两个维度。 例如: import torch a = torch.rand([64, 32, 3, 4]) b = torch.rand([64, 32, 3, 4]) c = torch.matmul(a, b.transpose(2, 3)) # 交换b的2,3两个维度 print(c.shape)