【发布时间】:2018-06-09 11:47:15
【问题描述】:
我的问题与here 类似,但不完全相同。我有两个张量
mu: (shape=(1000,1), dtype=np.float32)
p : (shape=(100,30), dtype=np.int64)
我想要的是创建一个新的张量
x : (shape=(100,30), dtype=np.float32)
这样
x[i,j] = mu[p[i,j]]
这可以使用高级索引在 numpy 中完成
x = mu[p]
我曾尝试使用tf.gather_nd(mu, p) 命令,但在我的情况下,我收到以下错误
*** ValueError: indices.shape[-1] must be <= params.rank, but saw indices shape: [100,30] and params shape: [1000] for 'GatherNd_2' (op: 'GatherNd') with input shapes: [1000], [100,30].
因此,为了使用它,我必须建立一个新的坐标张量。有没有更简单的方法来完成我想要的?
【问题讨论】:
标签: python numpy tensorflow