Python Practice › NumPy Programs › Program 54

Common elements of two arrays

EasyNumPy Programs · 54 of 100

Write a NumPy program to find the common elements of two arrays.

Advertisement
Input
[56, 18, 28, 36], [76, 36, 56]
Output
[36 56]

Approach

  1. np.intersect1d (sorted result).

Solution

Python
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.

More numpy programs

← All 100 NumPy Programs

Leave a Comment