如何找到两个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]
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下