numpy.ma.make_mask()函数| Python
numpy.ma.make_mask()函数用于从数组创建布尔掩码。
此函数可以接受任何可转换为整数或 nomask 的序列。它不要求内容必须是 0 和 1,值 0 被解释为 False,其他所有值都被解释为 True。返回 m 作为布尔掩码。
Syntax : numpy.ma.make_mask(m, copy = False, shrink = True, dtype = bool )
Parameters :
arr : [ array_like] Potential mask.
copy : [bool, optional] Whether to return a copy of m (True) or m itself (False).
shrink : [bool, optional] Whether to shrink m to nomask if all its values are False.
dtype : [dtype, optional] Data-type of the output mask. By default, the output mask has a dtype of MaskType (bool).
Return : [ndarray] A boolean mask derived from m.
代码#1:
Python3
# Python program explaining
# numpy.ma.make_mask() function
# importing numpy as geek
# and numpy.ma module as ma
import numpy as geek
import numpy.ma as ma
m = [1, 1, 0, 1]
gfg = ma.make_mask(m)
print (gfg)
Python3
# Python program explaining
# numpy.ma.make_mask() function
# importing numpy as geek
# and numpy.ma module as ma
import numpy as geek
import numpy.ma as ma
m = [2, -3, 0, 1]
gfg = ma.make_mask(m)
print (gfg)
Python3
# Python program explaining
# numpy.ma.make_mask() function
# importing numpy as geek
# and numpy.ma module as ma
import numpy as geek
import numpy.ma as ma
m = [True, True, True, False]
gfg = ma.make_mask(m)
print (gfg)
输出 :
[ True True False True]
代码#2:
Python3
# Python program explaining
# numpy.ma.make_mask() function
# importing numpy as geek
# and numpy.ma module as ma
import numpy as geek
import numpy.ma as ma
m = [2, -3, 0, 1]
gfg = ma.make_mask(m)
print (gfg)
输出 :
[ True True False True]
代码#3:
Python3
# Python program explaining
# numpy.ma.make_mask() function
# importing numpy as geek
# and numpy.ma module as ma
import numpy as geek
import numpy.ma as ma
m = [True, True, True, False]
gfg = ma.make_mask(m)
print (gfg)
输出 :
[ True True True False]