Python Practice › NumPy Programs › Program 54
Common elements of two arrays
Write a NumPy program to find the common elements of two arrays.
Input
[56, 18, 28, 36], [76, 36, 56]
Output
[36 56]
Approach
np.intersect1d(sorted result).
Solution
import numpy as npprint(np.intersect1d([56, 18, 28, 36], [76, 36, 56]))Output
[36 56]
Learn the concept
New to this topic? Read the lesson, then come back.