Pytorch学习之基础
一、基础学习
1.1 数据类型差异:
python | Pytorch |
Int | IntTensor of size |
float | FloatTensor of size |
Int array | IntTensor of size[d1,d2,...] |
Flaot array | FlaotTensor of size[d1,,,,] |
string | --无支持 |
如何表达字符:One- hot (类似哑变量),Embedding(编码器)
1.2 Type check
a = torch.randn(2,3)#2行,3列 a.type() 'torch.FloatTensor'
type(a)
torch.Tensor
isinstance(a,torch.FloatTensor)
1.2.1 标量
torch.tensor(2.3) #直接带入数据,形成标量
a.shape
len(a.shape)
a.dim() #返回值为0,为标量
1.2.2 张量(向量,,,,)
torch.tensor([1.1]) #dim=1的张良
torch.FloatTensor([1.1,2.2])
a.shape
torch.Size()