numpy.ma.ndenumerate#

ma.ndenumerate(a,compressed=True)[source]#

Multidimensional index iterator.

Return an iterator yielding pairs of array coordinates and values,skipping elements that are masked. Withcompressed=False,ma.masked is yielded as the value of masked elements. Thisbehavior differs from that ofnumpy.ndenumerate, which yields thevalue of the underlying data array.

Parameters:
aarray_like

An array with (possibly) masked elements.

compressedbool, optional

If True (default), masked elements are skipped.

See also

numpy.ndenumerate

Equivalent function ignoring any mask.

Notes

New in version 1.23.0.

Examples

>>>importnumpyasnp>>>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>>>amasked_array(  data=[[0, 1, 2],        [--, 4, --],        [6, --, 8]],  mask=[[False, False, False],        [ True, False,  True],        [False,  True, False]],  fill_value=999999)>>>forindex,xinnp.ma.ndenumerate(a):...print(index,x)(0, 0) 0(0, 1) 1(0, 2) 2(1, 1) 4(2, 0) 6(2, 2) 8
>>>forindex,xinnp.ma.ndenumerate(a,compressed=False):...print(index,x)(0, 0) 0(0, 1) 1(0, 2) 2(1, 0) --(1, 1) 4(1, 2) --(2, 0) 6(2, 1) --(2, 2) 8
On this page