2016-04-30 84 views
0

我正在嘗試使用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等效操作?

回答

1
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) 
+0

PS:用於與numpy的索引是另一個特徵奇偶錯誤https://github.com/tensorflow/tensorflow/issues/206 –