Overview:
-
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:
# Example Python program that uses numpy.equal() # Function to fill a 3x3 ndarray with double-precision # Create ndarray instances of double-precision floating point numbers fillDPArray(dpArray1) # Do not want all the results as False, as print("Array1:") print("Array2:") print("Array1 = Array2") |
Output:
Array1: [[1.78418893 1.34502285 1.84007858] [1.29815828 1.17697561 1.67392455] [1.63705878 1.85393845 1.24246788]] Array2: [[1.78418893 1.73576206 1.47579266] [1.44167562 1.47260249 1.42296846] [1.07237369 1.01274364 1.12999644]] Array1 = Array2 (Element-wise): [[ True False False] [False False False] [False False False]] |
Example 2:
# Example Python program to check for equality between exps1 = numpy.array([[5, 10.1, 15/5], exps2 = numpy.array([[5, 10.12, 15/5], |
Output:
[[ 5. 10.1 3. ] [-20. 25. 60. ] [100. 4. -6. ]] [[ 5. 10.12 3. ] [-20. 25. 60. ] [100. 4. -6. ]] [[ True False True] [ True True True] [ True True True]] |
Example 3:
# Example Python program that checks whether each import numpy # Create two ndarray instances and populate them with values numbers1[0][0] = 1.1 numbers2 = numpy.ndarray(shape = (2, 2), dtype=complex) results = numpy.equal(numbers1, numbers2) print("Array2:") print("Array1 == Array2:") |
Output:
Array1: [[1.1 +0.j 2. +0.j] [3.14+0.j 4. +2.j]] Array2: [[1.11 +0.j 2. +0.j] [3.141+0.j 4. -2.j]] Array1 == Array2: [[False True] [False False]] |