NumPy

Previous topic

numpy.lib.user_array.container

Next topic

numpy.ndenumerate.next

This is documentation for an old release of NumPy (version 1.18). Read this page in the documentation of the latest stable release (version 2.2).

numpy.ndenumerate

class numpy.ndenumerate(arr)[source]

Multidimensional index iterator.

Return an iterator yielding pairs of array coordinates and values.

Parameters
arrndarray

Input array.

See also

ndindex, flatiter

Examples

>>>
>>> a = np.array([[1, 2], [3, 4]])
>>> for index, x in np.ndenumerate(a):
...     print(index, x)
(0, 0) 1
(0, 1) 2
(1, 0) 3
(1, 1) 4

Methods

next(self)

Standard iterator method, returns the index tuple and array value.