1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
>>> a=torch.full((2, 2), 3) >>> a tensor([[3., 3.], [3., 3.]]) >>> >>> b = torch.ones(2, 2) >>> >>> torch.mm(a, b) tensor([[6., 6.], [6., 6.]]) >>> >>> torch.matmul(a, b) tensor([[6., 6.], [6., 6.]]) >>> >>> [email protected] tensor([[6., 6.], [6., 6.]]) >>> >>> >>> >>> a = torch.rand(4, 784) >>> >>> x = torch.rand(4, 784) >>> >>> w = torch.rand(512, 784) >>> >>> ([email protected]()).shape torch.Size([4, 512]) >>> >>> >>> >>> a = torch.rand(4, 3 ,28, 64) >>> b = torch.rand(4, 3, 64, 32) >>> >>> torch.mm(a, b).shape Traceback (most recent call last): File "<stdin>", line 1, in <module> RuntimeError: matrices expected, got 4D, 4D tensors at /pytorch/aten/src/TH/generic/THTensorMath.cpp:956 >>> >>> torch.matmul(a, b).shape torch.Size([4, 3, 28, 32]) >>> >>> b = torch.rand(4, 1, 64, 32) >>> >>> torch.matmul(a, b).shape torch.Size([4, 3, 28, 32]) >>> >>> b = torch.rand(4, 64, 32) >>> >>> torch.matmul(a, b).shape Traceback (most recent call last): File "<stdin>", line 1, in <module> RuntimeError: The size of tensor a (3) must match the size of tensor b (4) at non-singleton dimension 1
|
近期评论