zoukankan      html  css  js  c++  java
  • np.isin判断数组元素在另一数组中是否存在

    np.isin用法

    觉得有用的话,欢迎一起讨论相互学习~

    我的微博我的github我的B站

    • np.isin(a,b) 用于判定a中的元素在b中是否出现过,如果出现过返回True,否则返回False,最终结果为一个形状和a一模一样的数组。
    • 但是当参数invert被设置为True时,情况恰好相反,如果a中元素在b中没有出现则返回True,如果出现了则返回False.
    import numpy as np
    # 这里使用reshape是为了验证是否对高维数组适用,返回一个和a形状一样的数组
    a=np.array([1,3,7]).reshape(3,1)
    b=np.arange(9).reshape(3,3)
    # a 中的元素是否在b中,如果在b中显示True
    Np_No_invert=np.isin(a, b, invert=False)
    print("Np_No_invert
    ",Np_No_invert)
    # a 中的元素是否在b中,如果设置了invert=True,则情况恰恰相反,即a中元素在b中则返回False
    Np_invert=np.isin(a, b, invert=True)
    print("Np_invert
    ",Np_invert)
    # Np_No_invert
    #  [[ True]
    #  [ True]
    #  [ True]]
    # Np_invert
    #  [[False]
    #  [False]
    #  [False]]
    
  • 相关阅读:
    Atcoder 1975 Iroha and Haiku
    训练指南 string easy
    心态回归
    Mysql问题处理
    Mysql-从库只读设置
    Redis5-集群搭建实验
    安装python3并新建python3的虚拟环境
    docker-部署zabbix4
    pt工具-mysql慢日志分析&优化
    Ansible:playbook-nagios
  • 原文地址:https://www.cnblogs.com/cloud-ken/p/9927372.html
Copyright © 2011-2022 走看看