点乘/hadamard product
使用 torch.mul 。
In [14]: import numpy as npIn [15]: a = torch.from_numpy(np.arange(12).reshape(3, 4))In [16]: aOut[16]:tensor([[ 0, 1, 2, 3],[ 4, 5, 6, 7],[ 8, 9, 10, 11]], dtype=torch.int32)In [17]: b = torch.from_numpy(np.arange(12).reshape(3, 4))In [18]: c = torch.mul(a, b)In [19]: cOut[19]:tensor([[ 0, 1, 4, 9],[ 16, 25, 36, 49],[ 64, 81, 100, 121]], dtype=torch.int32)
使用 torch.mm 进行矩阵乘法matrix multiply。
In [21]: aOut[21]:tensor([[ 0, 1, 2, 3],[ 4, 5, 6, 7],[ 8, 9, 10, 11]], dtype=torch.int32)In [22]: b = torch.from_numpy(np.arange(12).reshape(4, 3))In [23]: d = torch.mm(a, b)In [24]: dOut[24]:tensor([[ 42, 48, 54],[114, 136, 158],[186, 224, 262]], dtype=torch.int32)
