mojo icon indicating copy to clipboard operation
mojo copied to clipboard

[Feature Request] [stdlib] Add `argsort` to the builtin `sort` module

Open martinvuyk opened this issue 8 months ago • 1 comments

Review Mojo's priorities

What is your request?

Add argsort similar to numpy's

What is your motivation for this change?

sorting inplace is not an option if you need to sort multiple arrays keeping the same permutations

Any other details?

I don't know what would be needed in terms of Span's capabilities. Because that permutation should be able to affect other items.

var my_list_distances = List[UInt64]()
var my_structures = List[MyStruct]()
...
var permutation = argsort(my_list_distances)
var ordered_structs = my_structures[permutation]

Or for now we can just return a list of indexes

martinvuyk avatar Jun 07 '24 14:06 martinvuyk