In [1]: import numpy as np
In [212]: x = np.arange(0,9).reshape(3,3)
In [213]: x
Out[213]:
array([[0, 1, 2],
[3, 4, 5],
[6, 7, 8]])
In [214]: x = np.ma.masked_where(x%4 == 0, x)
In [215]: x
Out[215]:
masked_array(data =
[[-- 1 2]
[3 -- 5]
[6 7 --]],
mask =
[[ True False False]
[False True False]
[False False True]],
fill_value = 999999)
In [216]: x.set_fill_value(-9999)
In [217]: x
Out[217]:
masked_array(data =
[[-- 1 2]
[3 -- 5]
[6 7 --]],
mask =
[[ True False False]
[False True False]
[False False True]],
fill_value = -9999)
In [218]: x.filled()
Out[218]:
array([[-9999, 1, 2],
[ 3, -9999, 5],
[ 6, 7, -9999]])
In [220]: x.filled(fill_value=9999)
Out[220]:
array([[9999, 1, 2],
[ 3, 9999, 5],
[ 6, 7, 9999]])