【发布时间】:2017-12-23 06:01:52
【问题描述】:
我有一个值张量和一个重新排序张量。重新排序张量为值张量中的每一行提供排序。如何使用这个重排序张量对值张量中的值进行实际重排序。
这会在 numpy (Indexing one array by another in numpy) 中给出所需的结果:
import numpy as np
values = np.array([
[5,4,100],
[10,20,500]
])
reorder_rows = np.array([
[1,2,0],
[0,2,1]
])
result = values[np.arange(values.shape[0])[:,None],reorder_rows]
print(result)
# [[ 4 100 5]
# [ 10 500 20]]
我怎样才能在 tf 中做同样的事情?
我尝试过使用切片和 tf.gather_nd 但无法成功。
谢谢。
【问题讨论】:
标签: python tensorflow slice