📜  numpy.ma.MaskedArray.toflex()函数– Python

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

numpy.ma.MaskedArray.toflex()函数– Python

numpy.ma.MaskedArray.toflex()函数将掩码数组转换为灵活类型数组。返回的灵活类型数组将有两个字段:_data 字段和 _mask 字段。 _data 字段存储数组的 _data 部分,_mask 字段存储数组的 _mask 部分。

代码#1:

# Python program explaining
# numpy.ma.MaskedArray.toflex() 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.toflex()
  
print (gfg)

输出 :

[[(1, False) (2,  True) (3, False)]
 [(4,  True) (5, False) (6,  True)]
 [(7, False) (8,  True) (9, False)]]


代码#2:

# Python program explaining
# numpy.ma.MaskedArray.toflex() function
  
# importing numpy as geek 
# and numpy.ma module as ma 
import numpy as geek 
import numpy.ma as ma 
  
arr = geek.ma.array([[11, 12, 13], [14, 15, 16], [17, 18, 19]], 
                                         mask =[0] + [1, 1]*4)
  
gfg = arr.toflex()
  
print (gfg)

输出 :

[[(11, False) (12,  True) (13,  True)]
 [(14,  True) (15,  True) (16,  True)]
 [(17,  True) (18,  True) (19,  True)]]