Thursday, July 9, 2026
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

1 COMMENT

Most Popular

Dominic
32519 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6901 POSTS0 COMMENTS
Nicole Veronica
12017 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12111 POSTS0 COMMENTS
Shaida Kate Naidoo
7020 POSTS0 COMMENTS
Ted Musemwa
7263 POSTS0 COMMENTS
Thapelo Manthata
6978 POSTS0 COMMENTS
Umr Jansen
6968 POSTS0 COMMENTS