How to do product of matrices in PyTorch

后端 未结 4 630
眼角桃花
眼角桃花 2020-12-12 18:02

In numpy I can do a simple matrix multiplication like this:

a = numpy.arange(2*3).reshape(3,2)
b = numpy.arange(2).reshape(2,1)
print(a)
print(b)
print(a.dot         


        
4条回答
  •  一生所求
    2020-12-12 18:18

    You can use "@" for computing a dot product between two tensors in pytorch.

    a = torch.tensor([[1,2],
                      [3,4]])
    b = torch.tensor([[5,6],
                      [7,8]])
    c = a@b #For dot product
    c
    
    d = a*b #For elementwise multiplication 
    d
    

提交回复
热议问题