Ruixiang
Ruixiang

Reputation: 23

how to get value from a index value

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]])?

Upvotes: 2

Views: 45

Answers (1)

Rxma
Rxma

Reputation: 312

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)

Upvotes: 2

Related Questions