在TensorFlow中对数组进行排序

Tim*_*man 14 python arrays sorting tensorflow

假设我在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], ..
Run Code Online (Sandbox Code Playgroud)

我想在第三列对这个数组进行排序.我该怎么做呢?我能够使用单独对每列进行排序tf.nn.top_k(),这为我提供了排序值和相应的索引.我可以使用第三列的索引对其他列重新排序,但我找不到重新排序的Op.

假设我想保持图形内容(没有Python恶作剧):

  • 如何在TensorFlow中对(上面的数组)进行排序?
  • 当我有重新订购的索引时,如何在TensorFlow中重新订购?

kev*_*man 12

以下作品:

a = tf.constant(...) # the array
reordered = tf.gather(a, tf.nn.top_k(a[:, 2], k=4).indices)
Run Code Online (Sandbox Code Playgroud)