all_nested_indices#
- ivy.all_nested_indices(nest=None, /, include_nests=False, _index=None, _base=True, extra_nest_types=None, *, out=None)[source]#
Return indices of all the elements in nest.
- Parameters:
nest (
Optional
[Union
[List
,Tuple
,Dict
,Array
,NativeArray
,Container
]]) – The nest to check the leaves of. (default:None
)include_nests (
bool
) – Whether to also include indices of the nests themselves, not only (default:False
) leaves. Default isFalse
._index (
Optional
[Union
[int
,Sequence
[int
]]]) – The indices detected so far. None at the beginning. Used internally, (default:None
) do not set manually._base (
bool
) – Whether the current function call is the first function call in the (default:True
) recursive stack. Used internally, do not set manually.extra_nest_types (
Optional
[Union
[Dtype
,Sequence
[Dtype
]]]) – Types to recursively check when deciding whether to go deeper into the (default:None
) nest or notout (
Optional
[Array
]) – Optional output array, for writing the result to. It must have a shape (default:None
) that the inputs broadcast to.
- Return type:
- Returns:
ret – A set of indices of all elements in nest
Both the description and the type hints above assumes an array input
for simplicity, but this function is nestable, and therefore also
accepts (class:ivy.Container instances in place of the arguments.)
Examples
With
Dict
input:>>> x = {'a': 2., 'b': [6., [15., 9.]], 'c': (7., 56.)} >>> y = ivy.all_nested_indices(x) >>> print(y) [['a'], ['b', 0], ['b', 1, 0], ['b', 1, 1], ['c', 0], ['c', 1]]
With
ivy.Array
input:>>> x = ivy.array([0., 1., 2., 3., 4.]) >>> y = ivy.all_nested_indices(x, False, out=x) >>> print(y) [[]]
With
ivy.Container
input:>>> x = ivy.Container(a=ivy.array([0., 1., 2.]), b=ivy.array([3., 4., 5.])) >>> y = ivy.all_nested_indices(x, True) >>> print(y) [['a'], ['b']]