【发布时间】:2016-06-08 22:42:00
【问题描述】:
gather(params, indices) 执行以下操作
output[i, ..., j, :, ... :] = params[indices[i, ..., j], :, ..., :]
所以如果你有 4 维参数和 2 维索引,你最终会得到 5 维数组
问题是怎么做
output[i, ..., j, :, ... :] = params[indices[i, :], ..., indices[j, :], :, ..., :]
使其充当numpy's
output = params[indices[0], indices[1], .. , :]
(github上的#206票是关于不同的问题:它是关于类似numpy的api,一般不收集)
一种可能的方法是使用gather_nd,但是(据我所知)如果我们想在并非所有维度上使用gather_nd,我们仍然必须为它们创建索引,例如如果我们有 10 维数组 A 并且我们想用 2 维数组 B 索引前两个维度,例如 A[B[0], B[1], :] 我们的索引矩阵必须有 11 列(有 8多余的)。
--- old indices ---- new index
0 0 <all rows of length 8> 0
1 1 <all rows of length 8> 1
...
【问题讨论】:
标签: python arrays numpy tensorflow