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]
药企,独角兽,苏州。团队长期招人,感兴趣的都可以发邮件聊聊:tiehan@sina.cn
个人公众号,比较懒,很少更新,可以在上面提问题,如果回复不及时,可发邮件给我: tiehan@sina.cn