Intersection of Numpy Arrays

If you want to get the intersection of two arrays, use the intersect1d() method in Numpy. Intersection means finding common elements between two arrays. In this lesson, we will see some examples:

  • Find the intersection between two arrays
  • Finding intersection sorts the resultant array
  • Find the intersection between two arrays with different elements

Find the intersection between two arrays

The intersect1d() method finds the intersection between two arrays. Let us see an example. We have created two integer arrays. We will find the intersection between these arrays:

Output

Finding intersection sorts the resultant array

The intersect1d() method finds the intersection and also sorts the result. Let us see an example. We have created two unsorted integer arrays. We will find the intersection between these arrays that will display a sorted result:

Output

Find the intersection between two arrays with different elements

Let us see what will happen when we find the intersection between two arrays with different elements. Therefore, both the arrays do not have even a single element similar.

Let us see the result:

Output

If you liked the tutorial, spread the word and share the link and our website Studyopedia with others.

For Videos, Join Our YouTube Channel: Join Now


Read More:

Axes in Numpy arrays
Difference between Numpy arrays
Studyopedia Editorial Staff
Studyopedia Editorial Staff
[email protected]

We work to create programming tutorials for all.

No Comments

Post A Comment

Discover more from Studyopedia

Subscribe now to keep reading and get access to the full archive.

Continue reading