• 技术文章 >Python技术 >Python基础教程

    Python中如何使用numpy.getmask()函数

    2021-04-06 15:25:50原创4332
    之前已经使用过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电脑。)

    专题推荐:numpygetmask函数 python
    上一篇:Python中numpy如何生成mask图像 下一篇:Python中numpy数组如何添加和删除元素

    相关文章推荐

    • python中numpy数据类型转换的方法• Python基础:numpy中any()和all()的用法• 基础学习:Python中numpy如何切片• Python中numpy如何索引• python实例:Python中如何删除numpy数组的元素• 详解Python中numpy.loadtxt()读取txt文件• Python中numpy如何生成mask图像

    全部评论我要评论

    © 2021 Python学习网 苏ICP备2021003149号-1

  • 取消发布评论
  • 

    Python学习网