数据结构
代码:
import torchx = torch.arange(12)##产生长度为12的一维张量print(x)##X = x.resize(3, 4)##被弃用##print(X)y = torch.reshape(x, (3, 4))##修改向量为矩阵,一维变二维print(y)print(y.size())xx = torch.zeros((2, 3, 4))##三维矩阵,高度2,其中宽为3,长为4print(xx)##自己创建张亮,通过python中的列表嵌套实现print(torch.tensor([1, 2, 3]))##一维张量
print(torch.tensor([[1, 2, 3], [1, 2, 3]]))##二维
print(torch.tensor([[[1, 2, 3], [1, 2, 3]], [[1, 2, 3], [1, 2, 3]]]))##三维
print(torch.tensor([[[[1, 2, 3], [1, 2, 3]], [[1, 2, 3], [1, 2, 3]]], [[[1, 2, 3], [1, 2, 3]], [[1, 2, 3], [1, 2, 3]]]]))##四维
##.....