0

Summary

I am applying tf.argsort() on a 3D matrix. I need to have the previous winner win ties.

Example

Array               ArgSort
[5, 10, 15, 20] --> [3, 2, 1, 0]
[5, 10, 15, 20] --> [3, 2, 1, 0]
[5,  5, 15, 20] --> [3, 2, 1, 0]
[4,  4, 12, 15] --> [3, 2, 1, 0]

In row 2, the second '5' should win because it won in row 1.

In a tie, I want to be able to look at the prior rows, and sort ties by previous winners.

Notes

Also, I need to be able to do this in parallel on the GPU. I might be able to implement it with thrust zip iterators instead, but tensorflow or numpy seemed the better option since I'm working with 3D matrices of various sizes, and because of the built in argsort.

John Mansell
  • 624
  • 5
  • 16
  • FWIW the property you are looking for is called [stable sorting](https://stackoverflow.com/questions/1517793/what-is-stability-in-sorting-algorithms-and-why-is-it-important) – maxy Jan 09 '20 at 20:57
  • Thanks. I'm actually looking for something a little different. I don't care what order they are in in the original array (which stable sorting preserves). I want them to be ranked by their weight, and then if there is a tie, rank them by who won in the previous column. Though admittedly, in my example the resultant argsort would be the same if stable sort is true. – John Mansell Jan 09 '20 at 21:23

0 Answers0