### 1、视图格式的含义[]
#### 图片格式 [b,28,28]
b:batch多少张图片,第一个28,代表图片有多少行,第二个28代表图片有多少28列
#### 图片格式 [b,28*28]
b:batch多少张图片,28*28代表图片的像素,抹除行列的概念。
#### 图片格式 [b,2,14*28]
多张图片,把图片分为上下两个部分,也抹除了行列的概念。
#### [b,28,28,1]
新增一个维度,可以代表RGB
### 2、Reshape
```py
a=tf.random.normal([4,28,28,3])
# 查看维度中的详细行
a.shape
# 查看有多少维度
a.ndim
# 变换维度
a=tf.reshape(a,[4,28*28,3])
#如果不知道维度具体是多少,可以用-1自动转换
a=tf.reshape(a,[4,-1,3])
```
### 3、tf.transpose 矩阵的转置
$content=[b,h,w,c]$
**注意:reshape在恢复维度的时候,width,height不要弄错**
```py
# 默认转换 T -> a.shape=([1,2,3,4])
a=tf.random.normal([4,3,2,1])
a=tf.transpose(a)
# 根据指定维度索引转换perm=[0,1,3,2]
# 0索引指向4,1索引只想3,3索引指向1,2索引指向2
# 所以结果为4,3,1,2
# a.shape=([4,3, 1,2])
a=tf.transpose(a,perm=[0,1,3,2])
```
### 4、增加维度和减少维度
#### 4.1 tf.expand_dims 增加维度
**E.g:**
$a=[classes,students,courses]$
$a2=[schools,classes,students,courses]$
```py
a=tf.random.normal([4,35,8])
# a.shape=([1,4,35,8])
tf.expand_dims(a,axis=0).shape
# 倒叙增加维度,a.shape=([4,35,8,1])
tf.expand_dims(a,axis=-1).shape
# 倒叙增加维度,a.shape=([1,4,35,8])
tf.expand_dims(a,axis=-4).shape
```
#### 4.2 tf.squeeze 减少维度(减少维度中为1的维度)
**E.g:**
$a=[4,35,8,1]$
$a2=[1,4,35,8]$
```py
#默认去除维度为1的全部维度 a.shape=([2,3])
tf.squeeze(tf.zeros([1,2,1,1,3])).shape
# 指定去除维度为1的维度, a.shape=([2,1,3])
a=tf.zeros([1,2,1,3])
tf.squeeze(a,axis=0).shape
# 倒叙去除 a.shape=([2,1,3])
tf.squeeze(a,axis=-4)
```

Tensorflow: 维度变换