本文所有内容摘自TensorFlow官方文档,仅用于自主学习使用。
tf.squeeze()函数主要用于“压缩”矩阵的维度,即删除输入Tensor(张量)的维度为“1”的那个维度信息,返回删除后的Tensor(张量)。
tf.squeeze(
input, axis=None, name=None
)
Returns | |
A Tensor . Has the same type as input . Contains the same data as input , but has one or more dimensions of size 1 removed. |
Raises | |
ValueError | The input cannot be converted to a tensor, or the specified axis cannot be squeezed. |
示例:
# '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]