I would like to make the following numpy code in Tensorflow:
input = np.array([[1,2,3]
[4,5,6]
[7,8,9]])
index1 = [0,1,2]
index2 = [2,2,0]
output = input[index1, index2]
>> output
[3,6,7]
given input, for example:
input = tf.constant([[1, 2, 3],
[4, 5, 6],
[7, 8, 9]])
I tried the following, but it seems to exceed:
index3 = tf.range(0, input.get_shape()[0])*input.get_shape()[1] + index2
output = tf.gather(tf.reshape(input, [-1]), index3)
sess = tf.Session()
sess.run(output)
>> [3,6,7]
This only works because my first index is convenient [0,1,2], but not feasible for [0,0,2], for example (except that it looks very long and ugly).
Will you have a simpler syntax, something more tensor / pythonic?