【问题标题】:How to tile a tensor in this way? (Tensorflow)如何以这种方式平铺张量? (张量流)
【发布时间】:2021-01-03 12:58:27
【问题描述】:

原点张量:

a = tf.constant([[1, 2, 3], [4, 5, 6], [7, 8, 9]])

我想要这样的张量:

result = [[1,2,3],[1,2,3],[1,2,3],[4,5,6],[4,5,6],[4,5,6],[7,8,9],[7,8,9],[7,8,9]]

使用 tile api 似乎不合适,有人可以帮忙吗?

【问题讨论】:

    标签: python tensorflow tile


    【解决方案1】:

    使用tf.repeat

    tf.repeat(a, repeats=3, axis=0)
    
    <tf.Tensor: shape=(9, 3), dtype=int32, numpy=
    array([[1, 2, 3],
           [1, 2, 3],
           [1, 2, 3],
           [4, 5, 6],
           [4, 5, 6],
           [4, 5, 6],
           [7, 8, 9],
           [7, 8, 9],
           [7, 8, 9]])>
    

    【讨论】:

      猜你喜欢
      • 2016-12-12
      • 1970-01-01
      • 2016-07-25
      • 1970-01-01
      • 2017-12-01
      • 2017-11-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多