import numpy as np
A = np.array([1, 1, 4.00003, 6])
B = np.array([2, 2, 4, 5])
is_A_B_equal = np.array_equal(A, B) # comparison is element wise
print(is_A_B_equal)
#------------------OUTPUT-----------------
False
#-----------------------------------------
# other logical operators for elements wise comparison:
print(np.greater(A, B))
print(np.greater_equal(A, B))
print(np.less(A, B))
print(np.less_equal(A, B))
print(np.isclose(A, B)) # isclose() takes floating point error into
# account, example 4 and 4.00003 are consider
# to be close enough within floating point
# tolerence.
#---------------OUTPUT-------------------
[False False True True]
[False False True True]
[ True True False False]
[ True True False False]
[False False True False]
#----------------------------------------
# Or if single logical value is needed then all() method can be used.
# all() returns true if all elements-wise comparison are true else it
# returns false. This is shown in output below:
print(np.greater(A, B).all())
print(np.greater_equal(A, B).all())
print(np.less(A, B).all())
print(np.less_equal(A, B).all())
print(np.isclose(A, B).all())
#-----------------OUTPUT-----------------
False
False
False
False
False
#------------------------------------------
# Furthermore any() can be used in place of all() method. any() method
#returns true if any element-wise comparison is true.