numpy.ma.filled() function return input as an array with masked data replaced by a fill value. If arr is not a MaskedArray, arr itself is returned. If arr is a MaskedArray and fill_value is None, fill_value is set to arr.fill_value.
Syntax : numpy.ma.filled(arr, fill_value = None)
Parameters :
arr : [MaskedArray or array_like] An input object.
fill_value : [scalar, optional] Filling value. Default is None.
Return : [ndarray] The filled array.
Code #1 :
Python3
# Python program explaining
# numpy.ma.filled() function
# importing numpy as geek
# and numpy.ma module as ma
import numpy as geek
import numpy.ma as ma
arr = geek.ma.array(geek.arange(4).reshape(2, 2),
mask =[[1, 0], [0, 1]])
gfg = arr.filled()
print (gfg)
Output :
[[999999 1]
[ 2 999999]]
Code #2 :
Python3
# Python program explaining
# numpy.ma.filled() function
# importing numpy as geek
# and numpy.ma module as ma
import numpy as geek
import numpy.ma as ma
arr = geek.ma.array(geek.arange(9).reshape(3, 3),
mask =[[1, 0, 0], [1, 0, 0], [0, 0, 0]])
gfg = arr.filled()
print (gfg)
Output :
[[999999 1 2]
[999999 4 5]
[ 6 7 8]]