📜  Python中的 numpy.setdiff1d()函数

📅  最后修改于: 2022-05-13 01:55:34.214000             🧑  作者: Mango

Python中的 numpy.setdiff1d()函数

numpy.setdiff1d()函数查找两个数组的集合差异,并返回 arr1 中不存在于 arr2 中的唯一值。

代码#1:

# Python program explaining
# numpy.setdiff1d() function
    
# importing numpy as geek 
import numpy as geek 
   
arr1 = [5, 6, 2, 3, 4]
arr2 = [1, 2, 3]
   
gfg = geek.setdiff1d(arr1, arr2)
   
print (gfg)

输出 :

[4 5 6]


代码#2:

# Python program explaining
# numpy.setdiff1d() function
    
# importing numpy as geek 
import numpy as geek 
   
arr1 = [1, 2, 3, 4, 5, 6, 7, 8, 9]
arr2 = [1, 3, 5, 7, 9, 11, 13, 15]
   
gfg = geek.setdiff1d(arr1, arr2)
   
print (gfg)

输出 :

[2 4 6 8]