1.数组访问元素
2.数据操作
x.shape #访问张量的形状
x.numel() #返回张量中元素的总数
a = x.reshape(3,4) #将x转换为3行4列
#a与x指向同一地址空间
torch.zeros((2,3,4))#形状为2 3 4 ,数据为全0
torch.ones((2,3,4))#形状为2 3 4 ,数据为全1
3.合并操作
x = torch.arange(12,dtype=torch.float32).reshape((3,4))
y = torch.tensor([[2.0,1,4,3],[1,2,3,4],[4,3,2,1]])
torch.cat((x,y),dim=0)# 将x,y在行上进行堆叠,形状为6行4列
torch.cat((x,y),dim=0) #将x,y在行上进 列 堆叠,形状为3行8列
4.广播机制
5.numpy 与 pytorch转换