【发布时间】:2017-11-30 10:09:41
【问题描述】:
我有两个如下形状的张量:
tensor1 => shape(10, 99, 106)
tensor2 => shape(10, 99)
tensor2 包含范围从0 - 105 的值,我希望用它来分割tensor1 的最后一个维度并获得形状的tensor3
tensor3 => shape(10, 99, 99)
我尝试过使用:
tensor4 = tf.gather(tensor1, tensor2)
# this causes tensor4 to be of shape (10, 99, 99, 106)
另外,使用
tensor4 = tf.gather_nd(tensor1, tensor2)
# gives the error: last dimension of tensor2 (which is 99) must be
# less than the rank of the tensor1 (which is 3).
我正在寻找类似于 numpy 的 cross_indexing 的东西。
【问题讨论】:
-
你确定
tensor3的形状吗?不应该是简单的 (10,99) 吗? -
是的。我希望使用来自
tensor2的 99 维向量,仅使用来自tensor1的第三维 (106) 的99值。
标签: python tensorflow tensor