how to get value from a index value

Viewed 28

The tensor is A_tensor,has shape [3,3,3] and I want get the last axis's value by index.

How do I do that in Tensorflow?

A_tensor =tf.constant([[1,2,3],[2,3,4],[3,4,5]])

How to get tensor ([[1,2],[2,3],[3,4]])?

1 Answers

You can use tf.gather():

A_tensor =tf.constant([[1,2,3],[2,3,4],[3,4,5]])
tf.gather(A_tensor,[[0,1]],axis=-1)
Related