reshape(合并维度)
a = tf.random.normal((4,28,28,3))
a_1 = tf.reshape(a,[4,784,3]).shape #1
a_1 = tf.reshape(a,[4,-1,3]).shape #和1等价
a_2 = tf.reshape(a,[4,784*3]).shape #2
a_2 = tf.reshape(a,[4,-1]).shape #和2等价
a
print (a_1)
print (a_2)
"""
28*28转为一个维度
28*28*3转为一个维度
(4, 784, 3)
(4, 2352)
"""
transpose(改变维度顺序)
a = tf.random.normal((4,28,28,3))
b =tf.transpose(a).shape #逆序输出
c =tf.transpose(a,perm=[0,1,3,2]).shape #定义输出顺序
print (b)
print (c)
"""
(3, 28, 28, 4)
(4, 28, 3, 28)
"""
expand_dims(增加)
a1 = tf.random.normal((4,35,8))
b1 = tf.expand_dims(a1,axis=0).shape
b2 = tf.expand_dims(a1,axis=3).shape
b3 = tf.expand_dims(a1,axis=-1).shape#倒数第一个位置
b4 = tf.expand_dims(a1,axis=-4).shape#倒数第四个位置
print (b1)
print (b2)
print (b3)
print (b4)
"""
(1, 4, 35, 8)
(4, 35, 8, 1)
(4, 35, 8, 1)
(1, 4, 35, 8)
"""
squeeze(减少)
s = tf.squeeze(tf.zeros([1,2,1,1,4])).shape #减少所有维度为1的维度
r1 = tf.zeros([1,2,1,3])
s1 = tf.squeeze(r1,axis=0).shape #减少下标为0的维度
s2 = tf.squeeze(r1,axis=-2).shape #减少下标为-2的维度
print (s)
print (s1)
print (s2)
"""
(2, 4)
(2, 1, 3)
(1, 2, 3)
"""