【问题标题】:Tensorflow: How to use a Ragged Tensor as an index into a normal tensor?Tensorflow:如何使用不规则张量作为正常张量的索引?
【发布时间】:2023-03-12 07:50:02
【问题描述】:

我有一个 2D RaggedTensor,其中包含我想要的完整张量每一行的索引,例如:

[
    [0,4],
    [1,2,3],
    [5]
]

进入

[
    [200, 305, 400, 20, 20, 105],
    [200, 315, 401, 20, 20, 167],
    [200, 7, 402, 20, 20, 105],
]

给予

[
    [200,20],
    [315,401,20],
    [105]
]

我怎样才能以最有效的方式实现这一点(最好只使用tf 函数)?我相信像 gather_nd 这样的东西能够使用 RaggedTensors,但我不知道它是如何工作的。

【问题讨论】:

    标签: tensorflow ragged ragged-tensors


    【解决方案1】:

    您可以使用tf.gatherbatch_dims 关键字参数:

    >>> tf.gather(tensor,indices,batch_dims=1)
    <tf.RaggedTensor [[200, 20], [315, 401, 20], [105]]>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-15
      • 2017-05-21
      • 2016-06-20
      • 1970-01-01
      • 2020-11-18
      相关资源
      最近更新 更多