Python 使用tf.gather或tf.gather\n进行切片

Python 使用tf.gather或tf.gather\n进行切片,python,tensorflow,Python,Tensorflow,我有一个大小为[batch\u size x actions\u space x N\u quantiles]的张量。为了便于示例,假设尺寸为2、3和4 x_test = <tf.Tensor: shape=(2, 3, 4), dtype=float32, numpy= array([[[-0.71722096, -0.36535808, -0.00286232, 0.37722322], [ 0.93776643, -1.146626 , 0.1840729

我有一个大小为[batch\u size x actions\u space x N\u quantiles]的张量。为了便于示例,假设尺寸为2、3和4

x_test = 
 <tf.Tensor: shape=(2, 3, 4), dtype=float32, numpy=
array([[[-0.71722096, -0.36535808, -0.00286232,  0.37722322],
        [ 0.93776643, -1.146626  ,  0.1840729 , -1.427474  ],
        [ 0.47025302, -0.92792755, -0.1490136 ,  1.495174  ]],

       [[-1.3838278 , -0.54772085, -0.14298695,  0.39195213],
        [-0.7986407 ,  0.6419045 , -0.8136323 ,  0.9346474 ],
        [ 0.96690583, -0.82267016, -0.51641494,  0.6930123 ]]],
      dtype=float32)>
如何使用tf.gather或tf.gather\n修复此问题。这应该非常简单,但我真的很难提取正确的数组。我试过这样的东西:

tf.gather(x_test, actions, axis=1) 

但是没有任何东西能正常工作

请尝试
tf.gather(x_测试,操作,批处理dims=1)
这很有效,非常感谢。虽然,即使在考虑了这些文件之后,我也不明白为什么哈哈
tf.gather(x_test, actions, axis=1)