{ } Raw JSON

bundles / numpy 2.4.4 / numpy / ma / extras / ndenumerate

function

numpy.ma.extras:ndenumerate

source: /numpy/ma/extras.py :1800

Signature

def   ndenumerate ( a compressed = True )

Summary

Multidimensional index iterator.

Extended Summary

Return an iterator yielding pairs of array coordinates and values, skipping elements that are masked. With compressed=False, ma.masked is yielded as the value of masked elements. This behavior differs from that of numpy.ndenumerate, which yields the value of the underlying data array.

Parameters

a : array_like

An array with (possibly) masked elements.

compressed : bool, optional

If True (default), masked elements are skipped.

Notes

Examples

import numpy as np
a = np.ma.arange(9).reshape((3, 3))
a[1, 0] = np.ma.masked
a[1, 2] = np.ma.masked
a[2, 1] = np.ma.masked
a
for index, x in np.ma.ndenumerate(a):
    print(index, x)
for index, x in np.ma.ndenumerate(a, compressed=False):
    print(index, x)

See also

numpy.ndenumerate

Equivalent function ignoring any mask.

Aliases

  • numpy.ma.ndenumerate