Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tensorflow ValueError: Shape must be rank 1 but is rank 2

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]

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

like image 818
Haitao Leng Avatar asked Nov 01 '16 18:11

Haitao Leng


1 Answers

You would want to use tf.gather_nd

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

Hope this helps.

like image 88
David Wong Avatar answered Sep 28 '22 06:09

David Wong