unravel_index#

ivy.unravel_index(indices, shape, /, *, out=None)[source]#

Convert a flat index or array of flat indices into a tuple of coordinate arrays.

Parameters:
  • indices (Union[Array, NativeArray]) – Input array.

  • shape (Tuple[int]) – The shape of the array to use for unraveling indices.

  • out (Optional[Array], default: None) – optional output array, for writing the result to.

Return type:

Tuple[Array]

Returns:

ret – Tuple with arrays of type int32 that have the same shape as the indices array.

Examples

>>> indices = ivy.array([22, 41, 37])
>>> ivy.unravel_index(indices, (7,6))
(ivy.array([3, 6, 6]), ivy.array([4, 5, 1]))
Array.unravel_index(self, shape, /, *, out=None)[source]#

ivy.Array instance method variant of ivy.unravel_index. This method simply wraps the function, and so the docstring for ivy.unravel_index also applies to this method with minimal changes.

Parameters:
  • self (Array) – Input array.

  • shape (Tuple[int]) – The shape of the array to use for unraveling indices.

  • out (Optional[Array], default: None) – optional output array, for writing the result to.

Return type:

Tuple[Array]

Returns:

ret – Tuple with arrays that have the same shape as the indices array.

Examples

>>> indices = ivy.array([22, 41, 37])
>>> indices.unravel_index((7,6))
(ivy.array([3, 6, 6]), ivy.array([4, 5, 1]))
Container.unravel_index(self, shape, /, *, out=None)[source]#

ivy.Container instance method variant of ivy.unravel_index. This method simply wraps the function, and so the docstring for ivy.unravel_index also applies to this method with minimal changes.

Parameters:
  • self (Container) – Input container including arrays.

  • shape (Union[Tuple[int], Container]) – The shape of the array to use for unraveling indices.

  • out (Optional[Container], default: None) – optional output array, for writing the result to.

Return type:

Container

Returns:

ret – Container with tuples that have arrays with the same shape as the arrays in the input container.

Examples

With one ivy.Container input: >>> indices = ivy.Container(a=ivy.array([22, 41, 37])), b=ivy.array([30, 2])) >>> indices.unravel_index((7, 6)) {

a: (ivy.array([3, 6, 6]), ivy.array([4, 5, 1])) b: (ivy.array([5, 0], ivy.array([0, 2])))

}