What is the numpy.char.greater_equal() function in Python?
Overview
The char.greater_equal() function in Python is used to check, one by one, if the elements of array x1 are greater than or equal to the elements of another array x2 of the same shape. It returns True if x1 is greater than or equal to x2 and False if otherwise.
Syntax
char.greater_equal(x1, x2)
Parameters
The char.greater_equal() function takes two parameter values, x1 and x2, which are the two input arrays of the same shape.
Return value
The char.greater_equal() function returns an output array of boolean values.
Example
Let’s look at the code below:
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.greater_equal() function on both arrays to see if they are equalprint(np.char.greater_equal(myarray1, myarray2))
Explanation
- Line 1: We import the
numpymodule. - Lines 4 to 5: We create the input arrays,
myarray1andmyarray2using thearray()function. - Lines 8 to 9: We print the arrays
myarray1andmyarray2. - Line 12: We implement the
char.greater_equal()function on both arrays to check if the elements inmyarray1are greater than or equal to the elements inmyarray2. We print the result to the console.