之前已经使用过numpy.mask()的小伙伴,可以试试numpy.getmask()函数,在numpy数组中也是频繁要用到的。
用法:
<p style="line-height: 1.75em"><span>numpy.get<a href="https://www.gaodaima.com/tag/ma" title="查看更多关于ma的文章" target="_blank">ma</a>sk(array)<br></span></p>
www#gaodaima.com来源gao@!dai!ma.com搞$$代^@码!网搞代码
返回:返回矩阵的掩码值。
范例1:
在这个例子中,我们可以通过使用numpy.getmask()方法,我们能够获得数组的掩码矩阵。
<p style="line-height: 1.75em"><span># 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>
输出:
<p style="line-height: 1.75em"><span>[[False False][ True False]]<br></span></p>
范例2:
<p style="line-height: 1.75em"><span># 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>
输出:
<p style="line-height: 1.75em"><span>[False True False False False]<br></span></p>
以上就是Python中numpy getmask()全部的用法及代码示例分析,更多Python学习推荐:云海天Python教程网。
来源:搞代码网:原文地址:https://www.gaodaima.com