The ndarray.__eq__() method of Numpy compares the values in ndarray to a specific value. It is useful to find which value in ndarray is equal to the given value.
It will return you a NumPy array with a boolean type having only values True and False.
Example
Python3
import numpy as np
gfg = np.array([1, 2, 3, 4, 5, 6])
print(gfg.__eq__(4))
|
Output[False False False True False False]
Syntax
Syntax: ndarray.__eq__($self, value, /)
Parameter
- self: The array on which the method is called.
- value: The value or array to compare with.
Return: New array with boolean values
How to Perform Element-wise Comparison in NumPy Array
Using __eq__() method of NumPy library we can compare two ndarray or compare a ndarray to a specific value.
Let us understand it better with an example:
Example
In this example, we can see that after applying numpy.__eq__(), we get the simple boolean array that can tell us which element in an array is equal to that of the provided parameter.
Python3
import numpy as np
gfg = np.array([[1, 2, 3, 4, 5, 6],
[6, 5, 4, 3, 2, 1]])
print(gfg.__eq__(4))
|
Output[[False False False True False False]
[False False True False False False]]
Last Updated :
05 Feb, 2024
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...