Friday, September 26, 2025
HomeLanguagesnumpy.ma.MaskedArray.tolist() function – Python

numpy.ma.MaskedArray.tolist() function – Python

numpy.ma.MaskedArray.tolist() function return the data portion of the masked array as a hierarchical Python list.

Syntax : numpy.ma.MaskedArray.tolist(fill_value = None)

Parameters :
axis : [scalar, optional] The value to use for invalid entries. Default is None.

Return : [list] The Python list representation of the masked array.

Code #1 :




# Python program explaining
# numpy.ma.MaskedArray.tolist() function
     
# importing numpy as geek   
# and numpy.ma module as ma  
import numpy as geek  
import numpy.ma as ma
    
arr = geek.ma.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]],
                               mask =[0] + [1, 0] * 4)
   
gfg = arr.tolist()
   
print (gfg)


Output :

[[1, None, 3], [None, 5, None], [7, None, 9]]

 
Code #2 :




# Python program explaining
# numpy.ma.MaskedArray.tolist() function
     
# importing numpy as geek   
# and numpy.ma module as ma  
import numpy as geek  
import numpy.ma as ma
    
arr = geek.ma.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]],
                              mask =[0] + [1, 0] * 4)
   
gfg = arr.tolist(-999)
   
print (gfg)


Output :

[[1, -999, 3], [-999, 5, -999], [7, -999, 9]]
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32321 POSTS0 COMMENTS
Milvus
84 POSTS0 COMMENTS
Nango Kala
6683 POSTS0 COMMENTS
Nicole Veronica
11854 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11910 POSTS0 COMMENTS
Shaida Kate Naidoo
6795 POSTS0 COMMENTS
Ted Musemwa
7071 POSTS0 COMMENTS
Thapelo Manthata
6756 POSTS0 COMMENTS
Umr Jansen
6762 POSTS0 COMMENTS