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 :



filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output :

[[999999      1]
 [     2 999999]]

 
Code #2 :

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output :

[[999999      1      2]
 [999999      4      5]
 [     6      7      8]]



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.