之前已经使用过numpy.mask()的小伙伴,可以试试numpy.getmask()函数,在numpy数组中也是频繁要用到的。用法:
1 | <p style= "line-height: 1.75em;" ><span style= "font-family: 微软雅黑, "Microsoft YaHei";" >numpy.getmask(array)<br></span></p>
|
返回:返回矩阵的掩码值。
范例1:
在这个例子中,我们可以通过使用numpy.getmask()方法,我们能够获得数组的掩码矩阵。
1 2 3 4 5 6 7 | <p style= "line-height: 1.75em;" ><span style= "font-family: 微软雅黑, "Microsoft YaHei";" > # import numpy
import numpy.ma as ma
gfg = ma.masked_equal([[1, 2], [5, 6]], 5)
# using numpy.getmask() method
rint(ma.getmask(gfg))<br></span></p>
|
输出:
1 | <p style= "line-height: 1.75em;" ><span style= "font-family: 微软雅黑, "Microsoft YaHei";" >[[False False][ True False]]<br></span></p>
|
范例2:
1 2 3 4 5 6 7 | <p style= "line-height: 1.75em;" ><span style= "font-family: 微软雅黑, "Microsoft YaHei";" > # import numpy
import numpy.ma as ma
gfg = ma.masked_equal([11, 12, 13, 14, 15], 12)
# using numpy.getmask() method
print(ma.getmask(gfg))<br></span></p>
|
输出:
1 | <p style= "line-height: 1.75em;" ><span style= "font-family: 微软雅黑, "Microsoft YaHei";" >[False True False False False]<br></span></p>
|
以上就是Python中numpy getmask()全部的用法及代码示例分析,更多Python学习推荐:PyThon学习网教学中心。
(推荐操作系统:windows7系统、Python 3.9.1,DELL G3电脑。)