ma.
masked_where
屏蔽满足条件的数组。
返回 a 作为一个被屏蔽的数组 condition 是True。任何屏蔽值 a 或 condition 在输出中也被屏蔽。
掩蔽条件。什么时候? condition 测试浮点值是否相等,请考虑使用 masked_values 相反。
masked_values
数组到掩码。
如果为真(默认值),则复制 a 结果。如果错误修改 a 就位并返回视图。
掩蔽的结果 a 在哪里? condition 是True。
参见
使用浮点等同性屏蔽。
masked_equal
当等于给定值时屏蔽。
masked_not_equal
面具在哪里 not 等于给定值。
masked_less_equal
小于或等于给定值的掩码。
masked_greater_equal
大于或等于给定值的掩码。
masked_less
当小于给定值时屏蔽。
masked_greater
大于给定值的掩码。
masked_inside
在给定间隔内屏蔽。
masked_outside
在给定间隔之外屏蔽。
masked_invalid
屏蔽无效值(NAN或INF)。
实例
>>> import numpy.ma as ma >>> a = np.arange(4) >>> a array([0, 1, 2, 3]) >>> ma.masked_where(a <= 2, a) masked_array(data=[--, --, --, 3], mask=[ True, True, True, False], fill_value=999999)
掩模阵列 b 有条件的 a .
>>> b = ['a', 'b', 'c', 'd'] >>> ma.masked_where(a == 2, b) masked_array(data=['a', 'b', --, 'd'], mask=[False, False, True, False], fill_value='N/A', dtype='<U1')
效果 copy 参数。
copy
>>> c = ma.masked_where(a <= 2, a) >>> c masked_array(data=[--, --, --, 3], mask=[ True, True, True, False], fill_value=999999) >>> c[0] = 99 >>> c masked_array(data=[99, --, --, 3], mask=[False, True, True, False], fill_value=999999) >>> a array([0, 1, 2, 3]) >>> c = ma.masked_where(a <= 2, a, copy=False) >>> c[0] = 99 >>> c masked_array(data=[99, --, --, 3], mask=[False, True, True, False], fill_value=999999) >>> a array([99, 1, 2, 3])
什么时候? condition 或 a 包含屏蔽值。
>>> a = np.arange(4) >>> a = ma.masked_where(a == 2, a) >>> a masked_array(data=[0, 1, --, 3], mask=[False, False, True, False], fill_value=999999) >>> b = np.arange(4) >>> b = ma.masked_where(b == 0, b) >>> b masked_array(data=[--, 1, 2, 3], mask=[ True, False, False, False], fill_value=999999) >>> ma.masked_where(a == 3, b) masked_array(data=[--, 1, --, --], mask=[ True, False, True, True], fill_value=999999)
numpy.ma