📜  Numpy MaskedArray.getdata() - Python

📅  最后修改于: 2022-05-13 01:55:39.352000             🧑  作者: Mango

Numpy MaskedArray.getdata() - Python

numpy.ma.getdata()函数用于将掩码数组的数据作为 ndarray 返回。如果 arr 是 MaskedArray,则将 arr 的数据作为 ndarray 返回,否则将 arr 作为 ndarray 或子类返回。

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

输出 :

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


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

输出 :

Input array :  [[1 3]
 [-- 8]]
Output array :  [[1 3]
 [5 8]]