searchsorted#
- ivy.searchsorted(x, v, /, *, side='left', sorter=None, ret_dtype='int64', out=None)[source]#
Return the indices of the inserted elements in a sorted array.
- Parameters:
x (
Union
[Array
,NativeArray
]) – Input array. If sorter is None, then it must be sorted in ascending order, otherwise sorter must be an array of indices that sort it.v (
Union
[Array
,NativeArray
]) – specific elements to insert in array x1side (
Literal
[‘left’, ‘right’]) – The specific elements’ index is at the ‘left’ side or (default:'left'
) ‘right’ side in the sorted array x1. If the side is ‘left’, the index of the first suitable location located is given. If ‘right’, return the last such index.ret_dtype (
Union
[Dtype
,NativeDtype
]) – the data type for the return value, Default: ivy.int64, (default:'int64'
) only integer data types is allowed.sorter (
Optional
[Union
[Array
,NativeArray
,List
[int
]]]) – optional array of integer indices that sort array x into ascending order, (default:None
) typically the result of argsort.out (
Optional
[Array
]) – optional output array, for writing the result to. (default:None
)
- Return type:
- Returns:
ret – An array of insertion points.
Examples
With
ivy.Array
input:>>> x = ivy.array([1, 2, 3]) >>> v = ivy.array([2]) >>> y = ivy.searchsorted(x, v) >>> print(y) ivy.array([1])
>>> x = ivy.array([0, 1, 2, 3]) >>> v = ivy.array([3]) >>> y = ivy.searchsorted(x, v, side='right') >>> print(y) ivy.array([4])
>>> x = ivy.array([0, 1, 2, 3, 4, 5]) >>> v = ivy.array([[3, 1], [10, 3], [-2, -1]]) >>> y = ivy.searchsorted(x, v) >>> print(y) ivy.array([[3, 1], [6, 3], [0, 0]])
- Array.searchsorted(self, v, /, *, side='left', sorter=None, ret_dtype='int64', out=None)#
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
- Container.searchsorted(self, v, /, *, side='left', sorter=None, ret_dtype='int64', key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)#
ivy.Container 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:
Container