nested_argwhere#
- ivy.nested_argwhere(nest, fn, check_nests=False, to_ignore=None, _index=None, _base=True, stop_after_n_found=None, extra_nest_types=None)[source]#
Check the leaf nodes of nested x via function fn, and returns all nest indices where the method evaluates as True.
- Parameters:
nest (
Iterable
) – The nest to check the leaves of.fn (
Callable
) – The conditon function, returning True or False.check_nests (
bool
) – Whether to also check the nests for the condition, not only nest leaves. (default:False
) Default isFalse
.to_ignore (
Optional
[Union
[type
,Tuple
[type
]]]) – Types to ignore when deciding whether to go deeper into the nest or not (default:None
)_index (
Optional
[List
]) – The indices detected so far. None at the beginning. Used internally, do not set (default:None
) manually._base (
bool
) – Whether the current function call is the first function call in the recursive (default:True
) stack. Used internally, do not set manually.stop_after_n_found (
Optional
[int
]) – to stop after some needed indices are found. (default:None
)extra_nest_types (
Optional
[Union
[type
,Tuple
[type
]]]) – Types to recursively check when deciding whether to go deeper into the (default:None
) nest or not
- Return type:
Union
[Iterable
,bool
]- Returns:
ret – A set of indices for the nest where the function evaluated as True.
Examples
With
List
input:>>> nest = [[[1, -2, 3], 19], [[9, -36, 80], -10.19]] >>> fun = ivy.abs >>> nested_indices = ivy.nested_argwhere(nest, fn=fun) >>> print(nested_indices) [ [0, 0, 0], [0, 0, 1], [0, 0, 2], [0, 1], [1, 0, 0], [1, 0, 1], [1, 0, 2], [1, 1] ]
With
Tuple
input:>>> nest = ([-5, 9, 2], [0.3, 4.]) >>> fun = ivy.abs >>> nested_indices = ivy.nested_argwhere(nest, fn=fun, stop_after_n_found=4) >>> print(nested_indices) [[0, 0], [0, 1], [0, 2], [1, 0]]
With
Dict
input:>>> nest={'a': [2., 0.6, -2.], 'b': [1., 4., 1.9], 'c': [9.4]} >>> fun = ivy.abs >>> nested_indices = ivy.nested_argwhere(nest, fn=fun) >>> print(nested_indices) [ ['a', 0], ['a', 1], ['a', 2], ['b', 0], ['b', 1], ['b', 2], ['c', 0] ]