Pytorch--基本数据类型
1、Python与Pytorch数据类型对比
Python | Pytorch |
---|---|
Int | IntTensor of size() |
float | FloatTensor of size() |
Int array | IntTensor of size [d1, d2 ,…] |
Float array | FloatTensor of size [d1, d2, …] |
string | – |
Pytorch中没有定义的string的类型的数据,想要表示有如下几种方法
One – hot
Word2Vec
GloVe详解
2、数据类型
2.1、常用的类型
- torch.FloatTensor
- torch.ByterTensor
- torch.IntTensor
2.2、判断类型的几种方法
GPU和CPU的Tensor是不一样的、通过cuda()可以将CPU的数据放置到GPU内。
3、Tensor的维度
3.1、0维
在Pytorch >0.3版本时候加入0维,一个单独的数字(虽然1维向量也是可以表示数字的,0.3版本以上便做了区分)
shape\size表示Tensor的形状
dim表示Tensor的维度
3.2、1维
常用于线性的输入
3.3、2维
Linear Input batch
线性输入加入个数维度
3.4、3维
常用于RNN Input Batch
3.5、4维
常用做图像处理
CNN:[b, c, h, w]
b:个数
c:颜色的通道
h:长
w:宽
3.6、高维
a.numel()表示Tensor的大小即(2328*28)