【问题标题】:Reducing the dimensions of a tensor in tensorflow [duplicate]减少张量流中张量的尺寸[重复]
【发布时间】:2021-12-08 12:17:58
【问题描述】:

我有一个形状如下的张量:

> tf.Tensor: shape=(1, 1440)

如何减少这样的形状,以便得到以下结果:

> tf.Tensor: shape=(1440,)

【问题讨论】:

    标签: python tensorflow


    【解决方案1】:

    使用tf.squeeze:

    import tensorflow as tf
    
    tensor = tf.random.uniform((1, 1440))
    print(tensor.shape
    
    TensorShape([1, 1440])
    

    现在:

    squeezed = tf.squeeze(tensor)
    print(squeezed.shape)
    
    TensorShape([1440])
    

    如果您真的想要形状的逗号格式,请将其转换为 NumPy:

    tf.squeeze(s).numpy().shape
    
    (1440,)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-17
      • 1970-01-01
      • 1970-01-01
      • 2015-09-16
      • 2017-09-19
      • 2019-09-13
      相关资源
      最近更新 更多