What is the numpy.char.less_equal() function in Python?
Overview
The char.less_equal() function in Python is used to check, element by element, if the elements of array1 are less than or equal to the elements of another array2 of the same size. This function returns True if array1[i] is less than or equal to array2[i]. Otherwise, it returns False.
Syntax
char.less_equal(x1, x2)
Parameter value
The char.less_equal() function takes two parameter values, x1 and x2, which are two input arrays of the same size.
Return value
The char.less_equal() function returns a boolean.
Code example
import numpy as np# creating input arraysmyarray1 = np.array(['1', '10', '122'])myarray2 = np.array(['1', '13', '121'])# printing the arraysprint(myarray1)print(myarray2)# implementing the char.less_equal() function on both arraysprint(np.char.less_equal(myarray1, myarray2))
Code explanation
- Line 1: We import the
numpylibrary. - Lines 4–5: We create the input arrays,
myarray1andmyarray2, using thearray()function. - Lines 8–9: We print the arrays
myarray1andmyarray2. - Line 12: We implement the
char.less_equal()function on both the arrays to check if the elements inmyarray1are less than or equal to the elements inmyarray2. And then, we print the results to the console.