
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How to find intersection between two Numpy arrays?
In this problem, we will find the intersection between two numpy arrays. Intersection of two arrays is an array with elements common in both the original arrays
Algorithm
Step 1: Import numpy. Step 2: Define two numpy arrays. Step 3: Find intersection between the arrays using the numpy.intersect1d() function. Step 4: Print the array of intersecting elements.
Example Code
import numpy as np array_1 = np.array([1,2,3,4,5]) print("Array 1:\n", array_1) array_2 = np.array([2,4,6,8,10]) print("\nArray 2:\n", array_2) intersection = np.intersect1d(array_1, array_2) print("\nThe intersection between the two arrays is:\n", intersection)
Output
Array 1: [1 2 3 4 5] Array 2: [2 4 6 8 10] The intersection between the two arrays is: [2 4]
- Related Articles
- How to find set difference between two Numpy arrays?
- How to find the intersection of two arrays in java?
- Intersection of two arrays JavaScript
- C++ program to find union and intersection of two unsorted arrays
- How to get the intersection of two arrays in MongoDB?
- Intersection of two arrays in Java
- Intersection of two arrays in C#
- Intersection of Two Arrays in C++
- Find Union and Intersection of two unsorted arrays in C++
- Intersection of Two Arrays II in Python
- C program to perform intersection operation on two arrays
- How to find the intersection between two or more lists in R?
- How to Create an Array using Intersection of two Arrays in JavaScript?
- How to find common elements between two Arrays using STL in C++?
- Matrix product of two arrays in Numpy

Advertisements