import torch a = torch.ones(5,3) #5*3的元素全为1的矩阵 print(a) b = torch.rand((5,3)) #5*3的元素为0-1之间的随机数的矩阵 print(b) c = torch.tensor([[1,2,3], [4,5,6], [7,8,9]]) print(c) d = torch.zeros(5,3, dtype=torch.long) #5*3的元素全为0的矩阵,dtype可以指定数据类型 print(d) print(a.type()) #输出为torch.FloatTensor print(b.type()) #输出为torch.FloatTensor print(c.type()) #输出为torch.LongTensor print(d.type()) #输出为torch.LongTensor