【发布时间】:2020-09-23 06:05:04
【问题描述】:
我有一个张量probs,其形状为(None, None, 110),代表LSTM 中的(batch_size, sequence_length, 110)。
我有另一个张量indices,其形状为(None, None),其中包含要从probs 的第三维中选择的元素的索引。
我想使用indices 来索引张量probs。
Numpy 等价物:
k, j = np.meshgrid(np.arange(probs.shape[1]), np.arange(probs.shape[0]))
indexed_probs = probs[j, k, indices]
由于probs 中的shape[0] 和shape[1] 未知,因此tf.meshgrid() 不是一个选项。
我找到了tf.gather、tf.gather_nd 和tf.batch_gather,但它们似乎都没有按照我的意愿行事。
有人知道怎么做吗?
【问题讨论】:
标签: python numpy tensorflow indexing tensorflow2.0