张量值错误:形状必须是第1级,但是是第2级

时间:2021-01-03 13:47:56
import tensorflow as tf
x = [[1,2,3],[4,5,6]]
y = [0,1]
z = [1,2]
x = tf.constant(x)
y = tf.constant(y)
z = tf.constant(z)
m = x[y,z]

What I expect is m = [2,6]

我期望的是m = [2,6]

I can get the result by theano or numpy. How I get the result using tensorflow?

我可以通过theano或numpy得到结果。如何使用tensorflow获得结果?

1 个解决方案

#1


5  

You would want to use tf.gather_nd

你需要使用tf.c en_nd

   slices = tf.gather_nd(x, [y, z])

Hope this helps.

希望这个有帮助。

#1


5  

You would want to use tf.gather_nd

你需要使用tf.c en_nd

   slices = tf.gather_nd(x, [y, z])

Hope this helps.

希望这个有帮助。