|
在numpy中,我可以像这样做一个简单的矩阵乘法:
- a = numpy.arange(2*3).reshape(3,2)
- b = numpy.arange(2).reshape(2,1)
- print(a)
- print(b)
- print(a.dot(b))
复制代码
然而,当我尝试用pytorch张量时,这是行不通的:
- a = torch.Tensor([[1, 2, 3], [1, 2, 3]]).view(-1, 2)
- b = torch.Tensor([[2, 1]]).view(2, -1)
- print(a)
- print(a.size())
- print(b)
- print(b.size())
- print(torch.dot(a, b))
复制代码
这段代码抛出以下错误:
RuntimeError: inconsistent tensor size at /Users/soumith/code/builder/wheel/pytorch-src/torch/lib/TH/generic/THTensorMath.c:503
|
|