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

CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online Exam Quiz O Level NIELIT Study material and Quiz Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Best Website and Software Company in Allahabad Website development Company in Allahabad