Indexing Matrix in TensorFlow
<p>For example, in Numpy I can get some values like this. </p>

<pre><code>d = np.array([[0, 1, 2], [3, 4, 5], [6, 7, 8]])
# array([[0, 1, 2],
#        [3, 4, 5],
#        [6, 7, 8]])

d[[0, 1, 2], [2, 1, 0]]
# array([2, 4, 6])
</code></pre>

<p>So I can retrieve [2, 4, 6]. </p>

<p>how can I do the same thing in TensorFlow?</p>

<pre><code>x = tf.Variable([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
init_op = tf.initialize_all_variables()
with tf.Session() as sess:
    sess.run(init_op)

print sess.run([x[[0, 1, 2], [2,1,0]]])[0]
</code></pre>

<p>it raises TypeError </p>

<pre><code>TypeError: Bad slice index [0, 1, 2] of type &lt;type 'list'&gt;
</code></pre>

<p>My Question is how can I get the same value through TensorFlow?</p>

<pre><code>print sess.run([x[[0, 1, 2], [2,1,0]]])[0]
</code></pre>

<p>One solution I found is to use gather_nd function. </p>

<pre><code>sess.run([tf.gather_nd(x, [[0, 2], [1, 1], [2, 0]])])
# [3 5 7]
</code></pre>

<p>Is there any other functions? a function more similar to Numpy in TensorFlow?</p>

python numpy neural-network tensorflow