Posts

Showing posts with the label compare two arrays in numpy

Compare two arrays in numpy | Data Science tutorial | codin india

Image
   Hey Friends! In today's post, we will learn how to compare two arrays in Numpy. For comparison in Numpy, we have two methods. == comparison operator or NumPy comparison operator Let us understand both methods one by one. 1. Using == operator We can do element to element-wise comparison using == operator.  Syntax:-   array1 == array2 Let us undestand it by Code:- Explanation:- In the above code, we created two arrays and then compare both of them with == operator. imported NumPy as np arr1 and arr2 are arrays print the result of the comparison OutPut Explanation :- It will compare both arrays element-wise i.e one element from one array to one element of another element and print the output. In the above example, it compared both arrays and gives output element-wise. 2. Using comparison operator We can compare array using a comparison operator also. It will also compare arrays element-wise and provide output as True or False.  We have standard Python comparison operators to compar