Programming Examples
Write a program to find the intersection of two arrays
Write a program to find the intersection of two arrays?
Solution
import numpy as np
# Create two arrays
array1 = np.array([1, 2, 3, 4, 5])
array2 = np.array([3, 4, 5, 6, 7])
# Find the intersection of the two arrays
intersection_result = np.intersect1d(array1, array2)
print("Array 1:", array1)
print("Array 2:", array2)
print("\nIntersection of the two arrays:")
print(intersection_result)
Output