indices#

ivy.indices(dimensions, *, dtype='int64', sparse=False)[source]#

Return an array representing the indices of a grid.

Parameters:
  • dimensions (Sequence[int]) – The shape of the grid.

  • dtype (Union[Dtype, NativeDtype], default: 'int64') – The data type of the result.

  • sparse (bool, default: False) – Return a sparse representation of the grid instead of a dense representation.

Return type:

Union[Array, Tuple[Array, ...]]

Returns:

ret – If sparse is False, returns one grid indices array of shape (len(dimensions),) + tuple(dimensions). If sparse is True, returns a tuple of arrays each of shape (1, …, 1, dimensions[i], 1, …, 1) with dimensions[i] in the ith place.

Examples

>>> ivy.indices((3, 2))
ivy.array([[[0 0]
            [1 1]
            [2 2]]
           [[0 1]
            [0 1]
            [0 1]]])
>>> ivy.indices((3, 2), sparse=True)
(ivy.array([[0], [1], [2]]), ivy.array([[0, 1]]))