- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

In this program, we will find the set difference of two numpy arrays. We will use the setdiff1d() function in the numpy library. This function takes two parameters: array1 and array2 and returns the unique values in array1 that are not in array2.

Step 1: Import numpy. Step 2: Define two numpy arrays. Step 3: Find the set difference between these arrays using the setdiff1d() function. Step 4: Print the output.

import numpy as np array_1 = np.array([2,4,6,8,10,12]) print("Array 1: \n", array_1) array_2 = np.array([4,8,12]) print("\nArray 2: \n", array_2) set_diff = np.setdiff1d(array_1, array_2) print("\nThe set difference between array_1 and array_2 is:\n",set_diff)

Array 1: [ 2 4 6 8 10 12] Array 2: [ 4 8 12] The set difference between array_1 and array_2 is: [ 2 6 10]

Array 1 has elements 2, 6, and 10 which are not in Array 2. Hence [2 6 10] are is the set difference between the two arrays.

- Related Questions & Answers
- How to find intersection between two Numpy arrays?
- Find the Symmetric difference between two arrays - JavaScript
- Find the compatibility difference between two arrays in C++
- Finding the difference between two arrays - JavaScript
- How to get the difference between two arrays in JavaScript?
- How to find common elements between two Arrays using STL in C++?
- How to find absolute difference between two numbers in MySQL?
- How to find the common elements between two or more arrays in JavaScript?
- Broadcasting with NumPy Arrays in Python
- Program to find minimum difference between two elements from two lists in Python
- Find difference between sums of two diagonals in C++.
- Find the difference between two datetime values with MySQL?
- Find minimum difference between any two element in C++
- Python Pandas – Find the Difference between two Dataframes
- How to find the intersection of two arrays in java?

Advertisements