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