Sorting#

ivy.invert_permutation(x, /)[source]#

Compute the inverse of an index permutation.

Parameters:

x (Union[Array, NativeArray, list, tuple]) – 1-D integer array-like, which represents indices of a zero-based array and is supposedly used to permute the array.

Return type:

Array

Returns:

ret – the inverse of the index permutation represented by ‘’x’’

Examples

>>> a = ivy.asarray([0, 3, 1, 2])
>>> ivy.invert_permutation(a)
ivy.array([0, 2, 3, 1])
ivy.lexsort(keys, /, *, axis=-1, out=None)[source]#

Perform an indirect stable sort with an array of keys in ascending order, with the last key used as primary sort order, second-to-last for secondary, and so on. Each row of the key must have the same length, which will also be the length of the returned array of integer indices, which describes the sort order.

Parameters:
  • keys (Union[Array, NativeArray]) – array-like input of size (k, N). N is the shape of each key, key can have multiple dimension.

  • axis (int, default: -1) – axis of each key to be indirectly sorted. By default, sort over the last axis of each key.

  • out (Optional[Array], default: None) – optional output array, for writing the result to.

Return type:

Array

Returns:

ret – array of integer(type int64) indices with shape N, that sort the keys.

Examples

>>> a = [1,5,1,4,3,4,4] # First column
>>> b = [9,4,0,4,0,2,1] # Second column
>>> ivy.lexsort([b, a]) # Sort by a, then by b
array([2, 0, 4, 6, 5, 3, 1])