Searching#
- class ivy.data_classes.container.searching._ContainerWithSearching(dict_in=None, queues=None, queue_load_sizes=None, container_combine_method='list_join', queue_timeout=None, print_limit=10, key_length_limit=None, print_indent=4, print_line_spacing=0, ivyh=None, default_key_color='green', keyword_color_dict=None, rebuild_child_containers=False, types_to_iteratively_nest=None, alphabetical_keys=True, dynamic_backend=None, **kwargs)[source]#
Bases:
ContainerBase
- _abc_impl = <_abc_data object>#
- static _static_argmax(x, /, *, axis=None, keepdims=False, dtype=None, select_last_index=False, out=None)[source]#
ivy.Container static method variant of ivy.argmax. This method simply wraps the function, and so the docstring for ivy.argmax also applies to this method with minimal changes.
- Parameters:
x (
Union
[Container
,Array
,NativeArray
]) – input array or container. Should have a numeric data type.axis (
Optional
[int
]) – axis along which to search. If None, the function must return the index of (default:None
) the maximum value of the flattened array. Deafult:None
.keepdims (
bool
) – If this is set to True, the axes which are reduced are left in the result as (default:False
) dimensions with size one. With this option, the result will broadcast correctly against the array.dtype (
Optional
[Union
[Dtype
,NativeDtype
]]) – Optional data type of the output array. (default:None
)out (
Optional
[Container
]) – If provided, the result will be inserted into this array. It should be of (default:None
) the appropriate shape and dtype.
- Return type:
Container
- Returns:
ret – a container containing the indices of the maximum values across the specified axis.
Examples
>>> x = ivy.Container(a=ivy.array([[4., 0., -1.], [2., -3., 6]]), ... b=ivy.array([[1., 2., 3.], [1., 1., 1.]]) >>> y = ivy.Container.static_argmax(x, axis=1, keepdims=True) >>> print(y) { a: ivy.array([[0], [2]]), b: ivy.array([[2], [0]]) }
- static _static_argmin(x, /, *, axis=None, keepdims=False, output_dtype=None, select_last_index=False, out=None)[source]#
ivy.Container static method variant of ivy.argmin. This method simply wraps the function, and so the docstring for ivy.argmin also applies to this method with minimal changes.
- Parameters:
x (
Union
[Container
,Array
,NativeArray
]) – input array or container. Should have a numeric data type.axis (
Optional
[int
]) – axis along which to search. If None, the function must return the index of (default:None
) the minimum value of the flattened array. Default = None.keepdims (
bool
) – if True, the reduced axes (dimensions) must be included in the result as (default:False
) singleton dimensions, and, accordingly, the result must be compatible with the input array (see Broadcasting). Otherwise, if False, the reduced axes (dimensions) must not be included in the result. Default = False.output_dtype (
Optional
[Union
[int32, int64]]) – An optional output_dtype from: int32, int64. Defaults to int64. (default:None
)out (
Optional
[Container
]) – optional output container, for writing the result to. It must have a shape (default:None
) that the inputs broadcast to.
- Return type:
Container
- Returns:
ret – a container containing the indices of the minimum values across the specified axis.
Examples
>>> x = ivy.Container(a=ivy.array([[4., 0., -1.], [2., -3., 6]]), ... b=ivy.array([[1., 2., 3.], [1., 1., 1.]]) >>> y = ivy.Container.static_argmin(axis=1, keepdims=True) >>> print(y) { a: ivy.array([[2], [1]]), b: ivy.array([[0], [0]]) }
- static _static_argwhere(x, /, *, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#
ivy.Container static method variant of ivy.argwhere. This method simply wraps the function, and so the docstring for ivy.argwhere also applies to this method with minimal changes.
- Parameters:
x (
Container
) – Boolean array, for which indices are desired.key_chains (
Optional
[Union
[List
[str
],Dict
[str
,str
]]]) – The key-chains to apply or not apply the method to. Default isNone
. (default:None
)to_apply (
bool
) – If True, the method will be applied to key_chains, otherwise key_chains will (default:True
) be skipped. Default isTrue
.prune_unapplied (
bool
) – Whether to prune key_chains for which the function was not applied. Default (default:False
) is False.map_sequences (
bool
) – Whether to also map method to sequences (lists, tuples). (default:False
) Default isFalse
.
- Return type:
Container
- Returns:
ret – Indices for where the boolean array is True.
Examples
Using
ivy.Container
instance method>>> x = ivy.Container(a=ivy.array([1, 2]), b=ivy.array([3, 4])) >>> res = ivy.Container.static_argwhere(x) >>> print(res) { a: ivy.array([[0], [1]]), b: ivy.array([[0], [1]]) }
>>> x = ivy.Container(a=ivy.array([1, 0]), b=ivy.array([3, 4])) >>> res = ivy.Container.static_argwhere(x) >>> print(res) { a: ivy.array([[0]]), b: ivy.array([[0], [1]]) }
- static _static_nonzero(x, /, *, as_tuple=True, size=None, fill_value=0)[source]#
ivy.Container static method variant of ivy.nonzero. This method simply wraps the function, and so the docstring for ivy.nonzero also applies to this method with minimal changes.
- Parameters:
x (
Union
[Container
,Array
,NativeArray
]) – input array or container. Should have a numeric data type.as_tuple (
bool
) – if True, the output is returned as a tuple of indices, one for each (default:True
) dimension of the input, containing the indices of the true elements in that dimension. If False, the coordinates are returned in a (N, ndim) array, where N is the number of true elements. Default = True.size (
Optional
[int
]) – if specified, the function will return an array of shape (size, ndim). (default:None
) If the number of non-zero elements is fewer than size, the remaining elements will be filled with fill_value. Default = None.fill_value (
Number
) – when size is specified and there are fewer than size number of elements, (default:0
) the remaining elements in the output array will be filled with fill_value. Default = 0.
- Return type:
Container
- Returns:
ret – a container containing the indices of the nonzero values.
- static _static_where(condition, x1, x2, /, *, out=None)[source]#
ivy.Container static method variant of ivy.where. This method simply wraps the function, and so the docstring for ivy.where also applies to this method with minimal changes.
- Parameters:
condition (
Union
[Container
,Array
,NativeArray
]) – input array or container. Should have a boolean data type.x1 (
Union
[Container
,Array
,NativeArray
]) – input array or container. Should have a numeric data type.x2 (
Union
[Container
,Array
,NativeArray
]) – input array or container. Should have a numeric data type.out (
Optional
[Container
]) – optional output container, for writing the result to. It must have a shape (default:None
) that the inputs broadcast to.
- Return type:
Container
- Returns:
ret – a container containing the values of x1 where condition is True, and x2 where condition is False.
Examples
>>> x1 = ivy.Container(a=ivy.array([3, 1, 5]), b=ivy.array([2, 4, 6])) >>> x2 = ivy.Container(a=ivy.array([0, 7, 2]), b=ivy.array([3, 8, 5])) >>> res = ivy.Container.static_where((x1.a > x2.a), x1, x2) >>> print(res) { a: ivy.array([3, 7, 5]), b: ivy.array([2, 8, 6]) }
- argmax(*, axis=None, keepdims=False, dtype=None, select_last_index=False, out=None)[source]#
ivy.Container instance method variant of ivy.argmax. This method simply wraps the function, and so the docstring for ivy.argmax also applies to this method with minimal changes.
- Parameters:
self (
Container
) – input array or container. Should have a numeric data type.axis (
Optional
[int
]) – axis along which to search. If None, the function must return the index of (default:None
) the maximum value of the flattened array. Deafult:None
.keepdims (
bool
) – If this is set to True, the axes which are reduced are left in the result as (default:False
) dimensions with size one. With this option, the result will broadcast correctly against the array.dtype (
Optional
[Union
[Dtype
,NativeDtype
]]) – Optional output dtype of the container. (default:None
)out (
Optional
[Container
]) – If provided, the result will be inserted into this array. It should be of (default:None
) the appropriate shape and dtype.
- Return type:
Container
- Returns:
ret – a container containing the indices of the maximum values across the specified axis.
Examples
>>> a = ivy.array([[4., 0., -1.], [2., -3., 6]]) >>> b = ivy.array([[1., 2., 3.], [1., 1., 1.]]) >>> x = ivy.Container(a=a, b=b) >>> y = x.argmax(axis=1, keepdims=True) >>> print(y) { a: ivy.array([[0], [2]]), b: ivy.array([[2], [0]]) }
- argmin(*, axis=None, keepdims=False, output_dtype=None, select_last_index=False, out=None)[source]#
ivy.Container instance method variant of ivy.argmin. This method simply wraps the function, and so the docstring for ivy.argmin also applies to this method with minimal changes.
- Parameters:
self (
Container
) – input array or container. Should have a numeric data type.axis (
Optional
[int
]) – axis along which to search. If None, the function must return the index of (default:None
) the minimum value of the flattened array. Default = None.keepdims (
bool
) – if True, the reduced axes (dimensions) must be included in the result as (default:False
) singleton dimensions, and, accordingly, the result must be compatible with the input array (see Broadcasting). Otherwise, if False, the reduced axes (dimensions) must not be included in the result. Default = False.output_dtype (
Optional
[Union
[Dtype
,NativeDtype
]]) – An optional output_dtype from: int32, int64. Defaults to int64. (default:None
)out (
Optional
[Container
]) – optional output container, for writing the result to. It must have a shape (default:None
) that the inputs broadcast to.
- Return type:
Container
- Returns:
ret – a container containing the indices of the minimum values across the specified axis.
Examples
Using
ivy.Container
instance method:>>> x = ivy.Container(a=ivy.array([0., -1., 2.]), b=ivy.array([3., 4., 5.])) >>> y = x.argmin() >>> print(y) { a:ivy.array(1), b:ivy.array(0) }
>>> x = ivy.Container(a=ivy.array([[4., 0., -1.], [2., -3., 6]]), ... b=ivy.array([[1., 2., 3.], [1., 1., 1.]]) >>> y = x.argmin(axis=1, keepdims=True) >>> print(y) { a: ivy.array([[2], [1]]), b: ivy.array([[0], [0]]) }
- argwhere(*, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#
ivy.Container instance method variant of ivy.argwhere. This method simply wraps the function, and so the docstring for ivy.argwhere also applies to this method with minimal changes.
- Parameters:
self (
Container
) – Boolean array, for which indices are desired.key_chains (
Optional
[Union
[List
[str
],Dict
[str
,str
]]]) – The key-chains to apply or not apply the method to. Default isNone
. (default:None
)to_apply (
bool
) – If True, the method will be applied to key_chains, otherwise key_chains will (default:True
) be skipped. Default isTrue
.prune_unapplied (
bool
) – Whether to prune key_chains for which the function was not applied. Default (default:False
) is False.map_sequences (
bool
) – Whether to also map method to sequences (lists, tuples). (default:False
) Default isFalse
.
- Returns:
ret – Indices for where the boolean array is True.
Examples
Using
ivy.Container
instance method>>> x = ivy.Container(a=ivy.array([1, 2]), b=ivy.array([3, 4])) >>> res = x.argwhere() >>> print(res) { a: ivy.array([[0], [1]]), b: ivy.array([[0], [1]]) }
>>> x = ivy.Container(a=ivy.array([1, 0]), b=ivy.array([3, 4])) >>> res = x.argwhere() >>> print(res) { a: ivy.array([[0]]), b: ivy.array([[0], [1]]) }
- nonzero(*, as_tuple=True, size=None, fill_value=0)[source]#
ivy.Container instance method variant of ivy.nonzero. This method simply wraps the function, and so the docstring for ivy.nonzero also applies to this method with minimal changes.
- Parameters:
self (
Container
) – input array or container. Should have a numeric data type.as_tuple (
bool
) – if True, the output is returned as a tuple of indices, one for each (default:True
) dimension of the input, containing the indices of the true elements in that dimension. If False, the coordinates are returned in a (N, ndim) array, where N is the number of true elements. Default = True.size (
Optional
[int
]) – if specified, the function will return an array of shape (size, ndim). (default:None
) If the number of non-zero elements is fewer than size, the remaining elements will be filled with fill_value. Default = None.fill_value (
Number
) – when size is specified and there are fewer than size number of elements, (default:0
) the remaining elements in the output array will be filled with fill_value. Default = 0.
- Return type:
Container
- Returns:
ret – a container containing the indices of the nonzero values.
- where(x1, x2, /, *, out=None)[source]#
ivy.Container instance method variant of ivy.where. This method simply wraps the function, and so the docstring for ivy.where also applies to this method with minimal changes.
- Parameters:
self (
Container
) – input array or container. Should have a boolean data type.x1 (
Union
[Container
,Array
,NativeArray
]) – input array or container. Should have a numeric data type.x2 (
Union
[Container
,Array
,NativeArray
]) – input array or container. Should have a numeric data type.out (
Optional
[Container
]) – optional output container, for writing the result to. It must have a shape (default:None
) that the inputs broadcast to.
- Return type:
Container
- Returns:
ret – a container containing the values of x1 where condition is True, and x2 where condition is False.
Examples
>>> x1 = ivy.Container(a=ivy.array([3, 1, 5]), b=ivy.array([2, 4, 6])) >>> x2 = ivy.Container(a=ivy.array([0, 7, 2]), b=ivy.array([3, 8, 5])) >>> res = x1.where((x1.a > x2.a), x2) >>> print(res) { a: ivy.array([3, 7, 5]), b: ivy.array([2, 8, 6]) }