[1.0420, 0.2906, 0.3730]])
tensor([[1.0027, 0.2992, 0.3707],
[1.0420, 0.2906, 0.3730]])
为更直观的了解其用法...,下面以一个具体的例子进行讲解
a = torch.rand(4, 784)
# 物理意义为4张图片,全部打平为28*28的数据
# 在图片处理中经常需要使用降维操作,本例考虑将[4, 784]降维成[...w = torch.rand(784, 512)
out = torch.matmul(a, w)
print(out.shape)
输出为
torch.Size([4, 512])
而在对高于2维的矩阵进行运算时...,使用torch.mm时会报错
# 对于4维矩阵运算,在使用torch.mm时会报错
a = torch.rand(4, 1, 64, 32)
b = torch.rand(4, 3, 32, 64)...print(torch.mm(a, b).shape)
输出
RuntimeError: matrices expected, got 4D, 4D tensors at ..