使用张量进行索引

Indexing using a tensor

我正在尝试使用 Targmax 张量来索引张量。

在 numpy 中,您可以进行以下索引:

mat = np.random.uniform(size = 3*10*10).reshape((3,10,10))
indices = [np.array([0,0,1,2]),np.array([1,1,2,3]), np.array([1,3,0,3])]
mat[indices]

tensorflow中有没有等价的操作?

x = tf.constant([[1,2],[3,4]])
sess = tf.Session()
sess.run(tf.gather_nd(x,[[0,0],[1,1]]))

出来

array([1, 4], dtype=int32)