numpy.isin()

numpy.isin() 是一个用于判断元素是否存在于指定集合中的函数,返回与输入数组形状相同的布尔数组。参数包括element(输入数组)、test_elements(测试元素)、assume_unique(假设唯一,默认False)和invert(反转结果,默认False)。当invert为True时,函数返回值相反,表示元素不在test_elements中。需要注意,test_elements必须为array类型,否则会被视为整体。
摘要由CSDN通过智能技术生成

numpy.isin(element, test_elements, assume_unique=False, invert=False)
  Calculates element in test_elements, broadcasting over element only. Returns a boolean array of the same shape as element that is True where an element of element is in test_elements and False otherwise.

Parameters: element : array_like 
        Input array.
        
      test_elements : array_like
  The values against which to test each value of element. This argument is flattened if it is an array or array_like. See notes for behavior with non-array-like parameters.
  
      assume_unique : bool, optional
  If True, the input arrays are both assumed to be unique, which can speed up the calculation. Default is False. 
  
      invert : bool, optional
  If True, the values in the returned array are inverted, as if calculating element not in test_elements. Default is False. np.isin(a, b, invert=True) is equivalent to (but faster than) np.invert(np.isin(a, b)).

Returns:  isin : ndarray, bool
  Has the same shape as element. The values element[isin] are in test_elements.


接下来看看例子

这个函数用来判断elements是否在test_elements中,返回一个与elements相同形状的布尔值。

>>> element = 2*np.arange(
  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值