如何找到两个Numpy数组之间的交集?
在这个问题中,我们将找到两个numpy数组之间的交集。两个数组的交集是在两个原始数组中都具有共同元素的数组
算法
Step 1: Import numpy. Step 2: Define two numpy arrays. Step 3: Find intersection between the arrays using the numpy.intersect1d() function. Step 4: Print the array of intersecting elements.
范例程式码
import numpy as np
array_1 = np.array([1,2,3,4,5])
print("Array 1:\n", array_1)
array_2 = np.array([2,4,6,8,10])
print("\nArray 2:\n", array_2)
intersection = np.intersect1d(array_1, array_2)
print("\nThe intersection between the two arrays is:\n", intersection)输出结果Array 1: [1 2 3 4 5] Array 2: [2 4 6 8 10] The intersection between the two arrays is: [2 4]
热门推荐
10 读书祝福语女生短句简短
11 感谢同事新婚祝福语简短
12 感谢教官文案祝福语简短
13 员工聚会蛋糕祝福语简短
14 元宵发客户祝福语简短
15 给团队信心祝福语简短
16 医美的祝福语大全简短
17 异国姻缘的祝福语简短
18 兄妹拍照祝福语简短的话