tensor.matmul(tensor.T)和tensor @ tensor.T区别
tensor.matmul(tensor.T)和tensor @ tensor.T,都可以实现张量的矩阵乘法。
这将计算两个张量之间的矩阵乘法。 y1, y2, y3 将具有相同的值
tensor = torch.ones(4, 4)
y1 = tensor @ tensor.T
y2 = tensor.matmul(tensor.T)
y3 = torch.rand_like(tensor)
torch.matmul(tensor, tensor.T, out=y3)
print(f"y1为 \n {y1} \n y2为 \n {y2} \ny3为 \n {y3}")
结果为:
这将计算逐元素乘积。 z1, z2, z3 将具有相同的值
tensor = torch.ones(4, 4)
z1 = tensor * tensor
z2 = tensor.matmul(tensor)
z3 = torch.rand_like(tensor)
torch.mul(tensor, tensor, out=z3)
print(f"z1为 \n {z1} \n z2为 \n {z2} \nz3为 \n {z3}")
结果为: