import numpy as np
import tensorflow as tf
'''
移除张量形状中大小为1的维度
'''
x = np.array([[[[2], [1]]]])
print(x.shape) #(1, 1, 2, 1)
x0 = tf.squeeze(x, axis =0)
print(x0.shape) #(1, 2, 1)
x1 = tf.squeeze(x, axis = 1)
print(x1.shape) #(1, 2, 1)
x3 = tf.squeeze(x, axis = 3)
print(x3.shape) #(1, 1, 2)
x2 = tf.squeeze(x, axis = 2)
print(x2.shape) #报错
'''
Can not squeeze dim[2], expected a dimension of 1,
2 for 'Squeeze_10' (op: 'Squeeze') with input shapes: [1,1,2,1]
'''
移除张量中大小为1的维度