import torch a = torch.randn(2, 2) print(a) print(a.shape) #张量的形状 (沿每个轴的长度) print(len(a)) print(a.numel()) #张量中元素的总数
reshape(x,y,z)
import torch b=torch.arange(12) print(b) print("----") print(b.reshape(3,4)) print(b.reshape(-1,4)) print(b.reshape(3,-1)) print(b.reshape(2,2,3)) print(b.reshape(2,2,-1)) #
print(b.reshape(2,3,2)) #大空行分开2行,每行中有三行,有2列