总结放前面
a&b=torch.mul(a,b) 矩阵各元素对位相乘
torch.mm(a,b)=torch.matmul(a,b) 矩阵乘法
初始化两个矩阵
input=torch.rand([4,4],dtype=torch.float64)
a=torch.randint(0,high=2,size=[4,4],dtype=torch.float64)
打印矩阵input,a值如下:
tensor([[0.2144, 0.0409, 0.8645, 0.3426],
[0.9860, 0.8908, 0.1770, 0.1409],
[0.2202, 0.5774, 0.5549, 0.1352],
[0.5474, 0.7407, 0.5088, 0.9849]], dtype=torch.float64)
tensor([[1., 0., 1., 0.],
[0., 1., 0., 1.],
[1., 0., 0., 1.],
[1., 1., 1., 0.]], dtype=torch.float64)
a*b
矩阵各个元素对位相乘
tensor([[0.2144, 0.0000, 0.8645, 0.0000],
[0.0000, 0.8908, 0.0000, 0.1409],
[0.2202, 0.0000, 0.0000, 0.1352],
[0.5474, 0.7407, 0.5088, 0.0000]], dtype=torch.float64)
torch.mul(a,b)
矩阵各个元素对位相乘
tensor([[0.2144, 0.0000, 0.8645, 0.0000],
[0.0000, 0.8908, 0.0000, 0.1409],
[0.2202, 0.0000, 0.0000, 0.1352],
[0.5474, 0.7407, 0.5088, 0.0000]], dtype=torch.float64)
torch.mm(a,b)
矩阵乘法
tensor([[1.4215, 0.3835, 0.5570, 0.9054],
[1.3040, 1.0317, 1.1269, 1.0678],
[0.9104, 0.7126, 0.3554, 1.1324],
[2.0411, 1.7256, 1.5323, 1.2494]], dtype=torch.float64)
torch.matmul(a,b)
矩阵乘法
tensor([[1.4215, 0.3835, 0.5570, 0.9054],
[1.3040, 1.0317, 1.1269, 1.0678],
[0.9104, 0.7126, 0.3554, 1.1324],
[2.0411, 1.7256, 1.5323, 1.2494]], dtype=torch.float64)