matmul 相当于利用广播机制的点积
true_w = torch.tensor([2,-3.4])
X = torch.normal(0,1,(2,len(true_w)))
y = torch.matmul(X,true_w)
print(X)
print(true_w)
print(y)
tensor([[-0.8593, -1.6781], [ 0.9634, -0.7398]])
tensor([ 2.0000, -3.4000])
tensor([3.9871, 4.4420])
torch.dot(X[0,],true_w)
tensor(3.9871)
和y[0]一样
本文通过一个具体的示例介绍了如何使用PyTorch进行矩阵乘法运算,并展示了如何通过.matmul()函数来实现矩阵之间的点积计算。此外,还对比了.matmul()与.dot()两种方法在不同情况下的应用。
1262

被折叠的 条评论
为什么被折叠?



