numpy.ma.ndenumerate#

ma.ndenumerate(a, compressed=True)[源代码]#

多维索引迭代器.

返回一个迭代器,该迭代器产生数组坐标和值的对,跳过被屏蔽的元素. 对于 compressed=False , ma.masked 被作为屏蔽元素的值产生. 此行为与 numpy.ndenumerate 的行为不同,后者会产生基础数据数组的值.

参数:
aarray_like

一个具有(可能)屏蔽元素的数组.

compressedbool, 可选

如果为 True(默认),则跳过屏蔽元素.

参见

numpy.ndenumerate

忽略任何掩码的等效函数.

注释

在 1.23.0 版本加入.

示例

>>> 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
masked_array(
  data=[[0, 1, 2],
        [--, 4, --],
        [6, --, 8]],
  mask=[[False, False, False],
        [ True, False,  True],
        [False,  True, False]],
  fill_value=999999)
>>> for index, x in np.ma.ndenumerate(a):
...     print(index, x)
(0, 0) 0
(0, 1) 1
(0, 2) 2
(1, 1) 4
(2, 0) 6
(2, 2) 8
>>> for index, x in np.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