Python Practice › NumPy Programs › Program 57

Union of two arrays

EasyNumPy Programs · 57 of 100

Write a NumPy program to find the union of two arrays.

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

Approach

  1. np.union1d.

Solution

Python
import numpy as npprint(np.union1d([56, 18, 28, 36], [76, 36, 56]))
Output
[18 28 36 56 76]

Learn the concept

New to this topic? Read the lesson, then come back.

More numpy programs

← All 100 NumPy Programs

Leave a Comment