Find common values between two NumPy arrays Last Updated : 29 Aug, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report In this article, we are going to discuss how to find out the common values between 2 arrays. To find the common values, we can use the numpy.intersect1d(), which will do the intersection operation and return the common values between the 2 arrays in sorted order. Syntax: numpy.intersect1d(arr1, arr2, assume_unique = False, return_indices = False) Parameters :arr1, arr2 : [array_like] Input arrays.assume_unique : [bool] If True, the input arrays are both assumed to be unique, which can speed up the calculation. Default is False.return_indices : [bool] If True, the indices which correspond to the intersection of the two arrays are returned. The first instance of a value is used if there are multiple. Default is False. Return : [ndarray] Sorted 1D array of common and unique elements. Example #1: Finding common values between 1d arrays Python3 import numpy as np # create 2 arrays a = np.array([2, 4, 7, 1, 4]) b = np.array([7, 2, 9, 0, 5]) # Display the arrays print("Original arrays", a, ' ', b) # use the np.intersect1d method c = np.intersect1d(a, b) # Display result print("Common values", c) Output: Original arrays [2 4 7 1 4] [7 2 9 0 5] Common values [2 7] Example #2: Finding common values between n-dimensional arrays Python3 import numpy as np # create 2 arrays a = np.array([2,4,7,1,4,9]).reshape(3,2) b = np.array([7,2,9,0,5,3]).reshape(2,3) # Display the arrays print("Original arrays") print(a) print(b) # use the np.intersect1d method c = np.intersect1d(a,b) # Display result print("Common values",c) Output: Original arrays [[2 4] [7 1] [4 9]] [[7 2 9] [0 5 3]] Common values [2 7 9] Note: No matter what dimension arrays are passed, the common values will be returned in a 1d flattened manner Comment More infoAdvertise with us Next Article How to remove NaN values from a given NumPy array? K KaranGupta5 Follow Improve Article Tags : Python Python-numpy Python numpy-arrayManipulation Practice Tags : python Similar Reads Calculate average values of two given NumPy arrays Finding average of NumPy arrays is quite similar to finding average of given numbers. We just have to get the sum of corresponding array elements and then divide that sum with the total number of arrays. Let's see an example: Example 1: Calculate average values of two given NumPy 1d-arrays Python3 # 1 min read How to find the Index of value in Numpy Array ? In this article, we are going to find the index of the elements present in a Numpy array.Using where() Methodwhere() method is used to specify the index of a particular element specified in the condition.Syntax: numpy.where(condition[, x, y])Example 1: Get index positions of a given valueHere, we fi 5 min read How to remove NaN values from a given NumPy array? In this article, we are going to learn how to remove Nan values from a given array. Nan values are those values that do not have a specific value associated with them or they are different from the type of values that are to be used in the declared array. There are basically three approaches with sl 3 min read How to Change a Single Value in a NumPy Array NumPy arrays are a fundamental data structure in Python, widely used for scientific computing and data analysis. They offer a powerful way to perform operations on large datasets efficiently. One common task when working with NumPy arrays is changing a single value within the array. This article wil 6 min read How to get values of an NumPy array at certain index positions? Sometimes we need to remove values from the source Numpy array and add them at specific indices in the target array. In NumPy, we have this flexibility, we can remove values from one array and add them to another array. We can perform this operation using numpy.put() function and it can be applied t 4 min read Python | Numpy np.ma.common_fill_value() method With the help of np.ma.common_fill_value() method, we can get the common filling values from both the masked array if same by using np.ma.common_fill_value() method. Syntax : np.ma.common_fill_value(array1, array2) Return : Return the common filling value from both the arrays. Example #1 : In this e 1 min read Like