I want to compare two arrays element-wise. The element-wise comparison should return a truth value of (a >= b or a<=b). Is there any Python function for such a comparison?

+1 vote

Best answer

You can use Numpy function greater_equal() or less_equal(). It will compare arrays element-wise and will return truth values.

Here is an example:

>>> import numpy as np

>>> a = np.array([1001, 1002, 1003, 1004])

>>> b = np.array([1011, 1002, 1003, 1204])>>> print(np.greater_equal(a, b))

[False True True False]>>> print(np.less_equal(a, b))

[ True True True True]