multi_index_nest#

ivy.multi_index_nest(nest, indices, /)[source]#

Repeatedly index a nested object, using a tuple of tuples of indices or keys in the case of dicts.

Parameters:
  • nest (Union[List, Dict, Tuple, Array, NativeArray, Container]) – The nested object to slice.

  • indices (Iterable[Iterable[int]]) – A tuple of tuples of indices to apply.

Return type:

Iterable[Any]

Returns:

ret – The result elements through indexing the nested object.

Examples

With Tuple inputs:

>>> x = (1, 2)
>>> y = [[0]]
>>> z = ivy.multi_index_nest(x, y)
>>> print(z)
[1]

With ivy.Array inputs:

>>> x = ivy.array([[1., 2.],
...                [3., 4.]])
>>> y = [[0],[1]]
>>> z = ivy.multi_index_nest(x, y)
>>> print(z)
[ivy.array([1., 2.], ivy.array([3., 4.])]

With ivy.Container input:

>>> x = ivy.Container(a=ivy.array([1,2]),
...                   b=[30,40])
>>> y = ('a', ('b', 0))
>>> z = ivy.multi_index_nest(x, y)
>>> print(z)
[ivy.array([1, 2]), 30]

With Dict input:

>>> x = {'a': 0, 'b': [1, [2, 3]], 'c': (4, 5)}
>>> y = (('b', 1), 'a')
>>> z = ivy.multi_index_nest(x, y)
>>> print(z)
[[2, 3], 0]

With List inputs:

>>> x = [['a', 'b', 'c'],
...      ['d', 'e', 'f'],
...      ['g', ['h', 'i']]]
>>> y = [[2, 1, 0], [0, 1]]
>>> z = ivy.multi_index_nest(x, y)
>>> print(z)
['h', 'b']