张量是A_tensor
,形状为[3,3,3]
,我想通过索引获取最后一个轴的值。
如何在 Tensorflow 中做到这一点?
A_tensor =tf.constant([[1,2,3],[2,3,4],[3,4,5]])
如何获取张量([[1,2],[2,3],[3,4]])
?
最佳答案
您可以使用tf.gather()
:
A_tensor =tf.constant([[1,2,3],[2,3,4],[3,4,5]])
tf.gather(A_tensor,[[0,1]],axis=-1)
关于tensorflow - 如何从索引值中获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65622728/