1.3 张量操作与线性回归
张量的操作
拼接
torch.cat()
torch.cat(tensors, dim=0, out=None)t = torch.ones((2, 3))
t_0 = torch.cat([t, t], dim=0)
t_1 = torch.cat([t, t], dim=1)
print("t_0:{} shape:{}\nt_1:{} shape:{}".format(t_0, t_0.shape, t_1, t_1.shape))t_0:tensor([[1., 1., 1.],
[1., 1., 1.],
[1., 1., 1.],
[1., 1., 1.]]) shape:torch.Size([4, 3])
t_1:tensor([[1., 1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1., 1.]]) shape:torch.Size([2, 6])torch.stack()
切分
torch.chunk()
torch.split()
索引
torch.index_select()
torch.mask_select()
变换
torch.reshape()
torch.transpose()
torch.t()
torch.squeeze()
torch.unsqueeze()
张量的数学运算
torch.add()
torch.addcdiv()
torch.addcmul()
线性回归

最后更新于
