numpy.ma.MaskedArray.toflex() function – Python
numpy.ma.MaskedArray.toflex()
function transforms a masked array into a flexible-type array. The flexible type array that is returned will have two fields: the _data field and the _mask field. The _data field stores the _data part of the array and the _mask field stores the _mask part of the array.
Syntax : numpy.ma.MaskedArray.toflex(self)
Return : [ndarray] A new flexible-type ndarray with two fields: the first element containing a value, the second element containing the corresponding mask boolean. The returned record shape matches self.shape.
Code #1 :
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)
|
Output :
[[(1, False) (2, True) (3, False)]
[(4, True) (5, False) (6, True)]
[(7, False) (8, True) (9, False)]]
Code #2 :
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)
|
Output :
[[(11, False) (12, True) (13, True)]
[(14, True) (15, True) (16, True)]
[(17, True) (18, True) (19, True)]]
Last Updated :
05 May, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...