all_nested_indices#

ivy.all_nested_indices(nest=None, /, include_nests=False, _index=None, _base=True)[source]#

Return indices of all the elements in nest.

Parameters:
  • nest (Optional[Union[List, Tuple, Dict, Array, NativeArray, Container]], default: None) – The nest to check the leaves of.

  • include_nests (bool, default: False) – Whether to also include indices of the nests themselves, not only leaves. Default is False.

  • _index (Optional[Union[int, Sequence[int]]], default: None) – The indices detected so far. None at the beginning. Used internally, do not set manually.

  • _base (bool, default: True) – Whether the current function call is the first function call in the recursive stack. Used internally, do not set manually.

Return type:

List

Returns:

ret – A set of indices of all elements in nest

Examples

With List input:

>>> x = [189, [863, 672], [264, 384]]
>>> y = ivy.all_nested_indices(x)
>>> print(y)
[[0], [1, 0], [1, 1], [2, 0], [2, 1]]

With Tuple input:

>>> x = (189, (863, 672), (264, 384))
>>> y = ivy.all_nested_indices(x, include_nests=True)
>>> print(y)
[[0], [1, 0], [1, 1], [1], [2, 0], [2, 1], [2]]

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([[True, False], [False, False]])
>>> y = ivy.all_nested_indices(x)
>>> print(y)
[[]]

With ivy.Container input:

>>> x = ivy.Container(a=ivy.array([412, 948, 482]), b=ivy.array([168, 674, 341]))
>>> y = ivy.all_nested_indices(x)
>>> print(y)
[['a'], ['b']]