Saturday, August 30, 2025
HomeLanguagesnumpy.ma.filled() function – Python

numpy.ma.filled() function – Python

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 :




# 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 :




# 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]]
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32249 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6617 POSTS0 COMMENTS
Nicole Veronica
11792 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11838 POSTS0 COMMENTS
Shaida Kate Naidoo
6731 POSTS0 COMMENTS
Ted Musemwa
7013 POSTS0 COMMENTS
Thapelo Manthata
6689 POSTS0 COMMENTS
Umr Jansen
6701 POSTS0 COMMENTS