Previous Up Next

5.40.21  Sorting by permutation: sortperm

The sortperm command returns the permutation which sorts the given list in ascending order or the list sorted by the given permutation.

sortperm takes one or two arguments:

If called with one argument, sortperm returns the permutation which sorts the list V in ascending order. If called with two arguments, it returns a copy of V sorted according to P.

This command is useful when several lists of equal lengths need to be sorted in the same order. Sorting by permutation is optimally efficient.

Examples.


Previous Up Next