假设我在 TensorFlow 中有一个数组:
[ 0.12300211, 0.51767069, 0.13886075, 0.55363625],
[ 0.47279349, 0.50432992, 0.48080254, 0.51576483],
[ 0.84347934, 0.44505221, 0.88839239, 0.48857492],
[ 0.93650454, 0.43652734, 0.96464157, 0.47236174], ..
我想按第三列对这个数组进行排序。我该怎么做呢?我可以使用 tf.nn.top_k()
单独对每一列进行排序,这会为我提供排序后的值和相应的索引。我可以使用第三列的索引对其他列进行重新排序,但我找不到重新排序的操作。
假设我想在图形中保留内容(没有 Python 恶作剧):
- 如何在 TensorFlow 中对(上述数组)进行排序?
- 当我有重新排序的索引时,如何在 TensorFlow 中重新排序?
最佳答案
以下作品:
a = tf.constant(...) # the array
reordered = tf.gather(a, tf.nn.top_k(a[:, 2], k=4).indices)
关于python - 在 TensorFlow 中对数组进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40784941/