numpy.ma.filled() function – Python
Last Updated :
05 May, 2020
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 :
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 :
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]]
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...