The equal() function of NumPy does an element-wise comparison of two numpy array-likes and returns the result as a Boolean array. The result is a single Boolean value when input parameters are scalars.
The numpy.equal() function checks whether two NumPy array-likes are equal element-wise. If the pair of elements match the result is True. The result is False otherwise. The results are returned as an ndarray containing Boolean values. A single Boolean value is returned if the compared input types are scalars.
Example 1
python
# Example Python program that uses numpy.equal()
# to compare the elements of two ndarray instances
import numpy
import random
# Function to fill a 3x3 ndarray with double-precision
# floating point numbers
def fillDPArray(arr_in):
for x in range(0, 3):
for y in range(0, 3):
arr_in[x][y] = random.uniform(1, 2)
# Create ndarray instances of double-precision floating point numbers
dpArray1 = numpy.ndarray(shape = (3, 3), dtype = numpy.float64)
dpArray2 = numpy.ndarray(shape = (3, 3), dtype = numpy.float64)
fillDPArray(dpArray1)
fillDPArray(dpArray2)
# Do not want all the results as False, as
# we do not want to rely on the likelyhood of having
# random.uniform() generating two equal numbers in short
# span of time/interval
dpArray2[0, 0] = dpArray1[0, 0]
print("Array1:")
print(dpArray1)
print("Array2:")
print(dpArray2)
print("Array1 = Array2")
print("(Element-wise):")
results = numpy.equal(dpArray1, dpArray2)
print(results)
We'd like to use Google Analytics cookies to count visits and see which tutorials are useful.
They are only set if you accept. We don't use advertising cookies and we don't sell your data.
You can change your choice any time from “Your privacy choices” at the bottom of every page.
Privacy Policy
Your privacy choices
Your browser sent a Global Privacy Control signal, so analytics is off unless you turn it on here.
Strictly necessary
Remembers this choice in your browser. No cookies, nothing sent to anyone.Always on