tensorflow--张量变换--2--tf.squeeze
- 从tensor中删除所有大小是1的维度
- 如果不想删除所有大小是1的维度,可以通过squeeze_dims指定。
函数:
tf.squeeze(
input,
axis=None,
name=None,
squeeze_dims=None
)
例子
# 't' is a tensor of shape [1, 2, 1, 3, 1, 1]
tf.shape(tf.squeeze(t)) # [2, 3]
指定删除的维度
# 't' is a tensor of shape [1, 2, 1, 3, 1, 1]
tf.shape(tf.squeeze(t, [2, 4])) # [1, 2, 3, 1]
