📜  numpy.ma.make_mask()函数| Python

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

numpy.ma.make_mask()函数| Python

numpy.ma.make_mask()函数用于从数组创建布尔掩码。
此函数可以接受任何可转换为整数或 nomask 的序列。它不要求内容必须是 0 和 1,值 0 被解释为 False,其他所有值都被解释为 True。返回 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]