Sorting#
- class ivy.data_classes.array.sorting._ArrayWithSorting[source]#
Bases:
ABC
- _abc_impl = <_abc._abc_data object>#
- argsort(*, axis=-1, descending=False, stable=True, out=None)[source]#
ivy.Array instance method variant of ivy.argsort. This method simply wraps the function, and so the docstring for ivy.argsort also applies to this method with minimal changes.
- Parameters:
self (
Array
) – input array.axis (
int
, default:-1
) – axis along which to sort. If set to-1
, the function must sort along the last axis. Default:-1
.descending (
bool
, default:False
) – sort order. IfTrue
, the returned indices sortx
in descending order (by value). IfFalse
, the returned indices sortx
in ascending order (by value). Default:False
.stable (
bool
, default:True
) – sort stability. IfTrue
, the returned indices must maintain the relative order ofx
values which compare as equal. IfFalse
, the returned indices may or may not maintain the relative order ofx
values which compare as equal (i.e., the relative order ofx
values which compare as equal is implementation-dependent). Default:True
.out (
Optional
[Array
], default:None
) – optional output array, for writing the result to. It must have the same shape as input.
- Return type:
Array
- Returns:
ret – an array of indices. The returned array must have the same shape as
x
. The returned array must have the default array index data type.
Examples
>>> x = ivy.array([1, 5, 2]) >>> y = x.argsort(axis=-1, descending=True, stable=False) >>> print(y) ivy.array([1, 2, 0])
>>> x = ivy.array([9.6, 2.7, 5.2]) >>> y = x.argsort(axis=-1, descending=True, stable=False) >>> print(y) ivy.array([0, 2, 1])
- msort(*, out=None)[source]#
ivy.Array instance method variant of ivy.msort. This method simply wraps the function, and so the docstring for ivy.msort also applies to this method with minimal changes.
- Parameters:
self (
Array
) – input array.out (
Optional
[Array
], default:None
) – optional output array, for writing the result to.
- Return type:
Array
- Returns:
ret – sorted array of the same type and shape as a
Examples
>>> a = ivy.asarray([[8, 9, 6],[6, 2, 6]]) >>> a.msort() ivy.array( [[6, 2, 6], [8, 9, 6]] )
- searchsorted(v, /, *, side='left', sorter=None, ret_dtype='int64', out=None)[source]#
ivy.Array instance method variant of ivy.searchsorted.
This method simply wraps the function, and so the docstring for ivy.searchsorted also applies to this method with minimal changes.
- Return type:
Array
- sort(*, axis=-1, descending=False, stable=True, out=None)[source]#
ivy.Array instance method variant of ivy.sort. This method simply wraps the function, and so the docstring for ivy.sort also applies to this method with minimal changes.
- Return type:
Array
Examples
>>> x = ivy.array([7, 8, 6]) >>> y = x.sort(axis=-1, descending=True, stable=False) >>> print(y) ivy.array([8, 7, 6])
>>> x = ivy.array([8.5, 8.2, 7.6]) >>> y = x.sort(axis=-1, descending=True, stable=False) >>> print(y) ivy.array([8.5, 8.2, 7.6])
This should have hopefully given you an overview of the sorting submodule, if you have any questions, please feel free to reach out on our discord!