在多维上的Tensorflow embedding_lookup

我想选择这个张量的一部分。

A = tf.constant([[[1,1],[2,2],[3,3]],[[4,4],[5,5],[6,6]]])

A的输出将为

[[[1 1]
  [2 2]
  [3 3]]

 [[4 4]
  [5 5]
  [6 6]]]

我要从A选择的索引是[1,0]。我的意思是该张量的第一部分的[2 2]和第二部分的[4 4],所以我的预期结果是

[2 2]
[4 4]

如何使用embedding_lookup函数?

B = tf.nn.embedding_lookup(A,[1,0])

我已经尝试过了

但这不是我的期望。

[[[4 4]
  [5 5]
  [6 6]]

 [[1 1]
  [2 2]
  [3 3]]]

有人可以帮助我并说明如何做吗?

cxd345 回答:在多维上的Tensorflow embedding_lookup

尝试以下操作,

A = tf.constant([[[1,1],[2,2],[3,3]],[[4,4],[5,5],[6,6]]])
B = [1,0]
inds = [(a,b) for a,b in zip(np.arange(len(B)),B)]

C = tf.gather_nd(params=A,indices=inds)
本文链接:https://www.f2er.com/2766806.html

大家都在问