Artificial intelligent assistant

torchにおけるサイズ[N,1]と[1,N]の掛け合わせ方 torchA([N,1])B=A'([1,N])[N,N] `torch.matmul``torch.mm`A'A([1,1]) `A = [a_1, a_2, ..., a_N]'`C(i,j) for i in range(N): for j in range(N): C(i,j) = a_i * a_j

torch 1.6.0`matmul``mm`


>>> import torch
>>> a = torch.randn(3, 1)
>>> b = torch.randn(1, 3)
>>> a.size()
torch.Size([3, 1])
>>> b.size()
torch.Size([1, 3])
>>> torch.matmul(a, b)
tensor([[ 0.0096, 0.3664, 0.2490],
[-0.0145, -0.5553, -0.3773],
[ 0.0282, 1.0820, 0.7353]])
>>> torch.mm(a, b)
tensor([[ 0.0096, 0.3664, 0.2490],
[-0.0145, -0.5553, -0.3773],
[ 0.0282, 1.0820, 0.7353]])
>>> torch.matmul(b, a)
tensor([[0.1896]])

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy a835843ec532804d07c57d35bd28e05e