dpnp.ndindex

class dpnp.ndindex(*shape)[source]

An N-dimensional iterator object to index arrays.

Given the shape of an array, an dpnp.ndindex instance iterates over the N-dimensional index of the array. At each iteration a tuple of indices is returned, the last dimension is iterated over first.

For full documentation refer to numpy.ndindex.

Parameters:

shape (ints, or a single tuple of ints) -- The size of each dimension of the array can be passed as individual parameters or as the elements of a tuple.

See also

dpnp.ndenumerate

Multidimensional index iterator.

dpnp.flatiter

Flat iterator object to iterate over arrays.

Examples

>>> import dpnp as np

Dimensions as individual arguments

>>> for index in np.ndindex(3, 2, 1):
...     print(index)
(0, 0, 0)
(0, 1, 0)
(1, 0, 0)
(1, 1, 0)
(2, 0, 0)
(2, 1, 0)

Same dimensions - but in a tuple (3, 2, 1)

>>> for index in np.ndindex((3, 2, 1)):
...     print(index)
(0, 0, 0)
(0, 1, 0)
(1, 0, 0)
(1, 1, 0)
(2, 0, 0)
(2, 1, 0)