标签:tor col and color rand imp pytorch shape div
1、@是用来对tensor进行矩阵相乘的:
import torch d = 2 n=50 X = torch.randn(n,d) true_w = torch.tensor([[-1.0],[2.0]]) y = X @ true_w + torch.randn(n,1)*0.1 print(X.shape) print(y.shape) print(true_w.shape)
torch.Size([50, 2]) torch.Size([50, 1]) torch.Size([2, 1])
2、*用来对tensor进行矩阵进行逐元素相乘:
x = torch.tensor([[1,2],[3,4]]) y = torch.tensor([[2,1],[4,3]]) c = x*y print("x_shape",x.shape) print("y_shape",y.shape) print("c_shape",c.shape) print(c)
x_shape torch.Size([2, 2]) y_shape torch.Size([2, 2]) c_shape torch.Size([2, 2]) tensor([[ 2, 2], [12, 12]])
标签:tor col and color rand imp pytorch shape div
原文地址:https://www.cnblogs.com/peixu/p/13382962.html