原文:https://docs.scipy.org/doc/numpy/reference/generated/numpy.ma.masked_where.html
校对:(虚位以待)
numpy.ma.
masked_where
(condition, a, copy=True)[source]屏蔽满足条件的数组。
将a t>返回为屏蔽的数组,其中条件为True。任何屏蔽的a或条件也会在输出中被屏蔽。
参数: | condition:array_like
a:array_like
copy:bool
|
---|---|
返回: | result:MaskedArray
|
也可以看看
masked_values
masked_equal
masked_not_equal
masked_less_equal
masked_greater_equal
masked_less
masked_greater
masked_inside
masked_outside
masked_invalid
例子
>>> 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)
条件为a的掩码数组b。
>>> 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)
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])
当条件或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)