当我使用tf.gather_nd时,我遇到了一些问题,我的玩具代码是这样的,当我运行它时,它不会给出结果 正如所料。代码是这样的:
x = tf.constant([[0.22, 0.3,0.1,0.11],[0.4,0.5, 0.6,0.99],[0.8, 0.9,0.43,0.21]])
indices = tf.constant([[1,2],[0,1],[2,3]])
b=tf.gather_nd(x, indices)
sess = tf.InteractiveSession()
cc=sess.run([b], feed_dict={})
print cc
当我期望结果是浮点结果时,但结果像
一样全部为零[array([0,0,0。],dtype = float32)]
答案 0 :(得分:0)
尝试不使用tf.constant(),
x = [[0.22, 0.3,0.1,0.11],[0.4,0.5, 0.6,0.99],[0.8, 0.9,0.43,0.21]]
indices = [[1,2],[0,1],[2,3]]
b = tf.gather_nd(x, indices)
sess = tf.Session()
print (sess.run(b))