This is a pre-release version (2.5.0.dev0+git20251130.2de293a). Go to latest (2.4.4)
{ } Raw JSON

bundles / numpy 2.5.0.dev0+git20251130.2de293a / numpy / ndindex

class

numpy:ndindex

source: /dev/numpy/build-install/usr/lib/python3.14/site-packages/numpy/__init__.py

Signature

class   ndindex ( * shape )

Summary

An N-dimensional iterator object to index arrays.

Extended Summary

Given the shape of an array, an 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.

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.

Examples

import numpy as np
Dimensions as individual arguments
for index in np.ndindex(3, 2, 1):
    print(index)
Same dimensions - but in a tuple ``(3, 2, 1)``
for index in np.ndindex((3, 2, 1)):
    print(index)

See also

flatiter
ndenumerate

Aliases

  • numpy.ndindex