Python Practice › NumPy Programs › Program 56

Set difference

EasyNumPy Programs · 56 of 100

Write a NumPy program to find the unique values of array1 that are not in array2.

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

Approach

  1. np.setdiff1d.

Solution

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

Learn the concept

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

More numpy programs

← All 100 NumPy Programs