PyTorch数据类型 Tensor
类型查看
a=torch.randn(2,3)
- a.type()
- type(a)
- isinstance(a,torch.FloatTensor)
cuda 类型
- isinstance(data,torch.cuda.DoubleTensor)
是False - data=data.cuda()
- isinstance(data,torch.cuda.DoubleTensor)
是True
标量 (dim 0)
- a= torch.tenscor(1.)
返回一个tensor(1.) - a.shape
返回一个torch.Size([ ]) - a.size()
返回 torch.Size([ ]) - len(a.shape)
返回 0 - a.dim()
返回 0
0维tensor
向量 vector (dim 1)
- a=torch.tensor([1.1]) #括号里面是内容
返回一个tensor([1.1000]) - b= torch.tensor([1.1,2.2]) #括号里面是内容
返回一个tensor([1.1000,2.2000]) - c=torch.FloatTensor(1) #括号里面是shape
返回一个tensor([-1.3956e+19]) - d=torch.FloatTensor(2) #括号里面是shape
返回一个tensor([1.1832e+08, 4.5360e-41]) - data=np.ones(2) #从numpy引入
返回一个 array([1., 1.]) - e=torch.from_numpy(data)
e为 tensor([1.,1.],dtype=torch.float64)
Dim2
- a=torch.randn(2,3)
返回
tensor([[-1.4602, -1.0992, 1.1445],
[-2.6324, 0.3383, -0.3203]]) - a.shape
返回 torch.Size([2,3]) - a.size(0)
返回 2 - a.size(1)
返回 3 - a.shape[1]
返回 3