Overview:
-
The less() function of NumPy module compares the elements of two NumPy array-likes and returns the results in a Boolean array. If element1 is less than element2 than the result is True; The result is False otherwise. If the input parameters are scalars than a Boolean value is returned.
-
The less() function does the opposite of the greater() function.
Example:
The Python example uses random.uniform() to generate random floating point numbers between the given range of 5.1 and 9.1 and fills the ndarray objects.
# Example Python program that compares the elements # Function that fills a 3x3 ndarray with random # Create 3x3 ndarray to store floating point numbers # Create 3x3 ndarray to store floating point numbers # Fill the arrays print("Array1:") print("Array2:") # Compare using numpy.less() function print("Array1 < Array2:") |
Output:
Array1: [[7.01322589 7.75920796 6.29760756] [6.36789148 7.43626891 6.91623009] [7.03070352 6.74934007 6.1260513 ]] Array2: [[5.76370196 8.00060042 6.89754765] [8.54632546 8.67683287 6.35581307] [7.50265029 6.64350998 6.67909488]] Array1 < Array2: [[False True True] [ True True False] [ True False True]] |