Thursday, May 14, 2026
HomeLanguagesNumpy MaskedArray.getdata() – Python

Numpy MaskedArray.getdata() – Python

numpy.ma.getdata() function is used return the data of a masked array as an ndarray. Return the data of arr as an ndarray if arr is a MaskedArray, else return arr as a ndarray or subclass if not.

Syntax : numpy.ma.getdata(a, subok=True)

Parameters :
arr : [array_like] Input MaskedArray, alternatively a ndarray or a subclass thereof.
subok : [bool] Whether to force the output to be a pure ndarray (False) or to return a subclass of ndarray if appropriate (True, default).

Return : [ndarray] Return the data of a masked array as an ndarray.

Code #1 :




# Python program explaining
# numpy.ma.getdata() function
  
# importing numpy as geek  
# and numpy.ma module as ma 
import numpy as geek 
import numpy.ma as ma
  
arr = ma.masked_equal([[2, 4], [6, 8]], 4)
print("Input array : ", arr)
  
# applying numpy.ma.getdata() method
gfg = ma.getdata(arr)
print("Output array : ", gfg)


Output :

Input array :  [[2 --]
 [6 8]]
Output array :  [[2 4]
 [6 8]]

 
Code #2 :




# Python program explaining
# numpy.ma.getdata() function
  
# importing numpy as geek  
# and numpy.ma module as ma 
import numpy as geek 
import numpy.ma as ma
  
arr = ma.masked_equal([[1, 3], [5, 8]], 5)
print("Input array : ", arr)
  
# applying numpy.ma.getdata() method
gfg = ma.getdata(arr)
print("Output array : ", gfg)


Output :

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

2 COMMENTS

Most Popular

Dominic
32514 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6892 POSTS0 COMMENTS
Nicole Veronica
12012 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12107 POSTS0 COMMENTS
Shaida Kate Naidoo
7016 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6975 POSTS0 COMMENTS
Umr Jansen
6963 POSTS0 COMMENTS