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 arrays
myarray1 = np.array(['1', '10', '122'])
myarray2 = np.array(['1', '13', '121'])
# printing the arrays
print(myarray1)
print(myarray2)
# implementing the char.greater_equal() function on both arrays to see if they are equal
print(np.char.greater_equal(myarray1, myarray2))

Explanation

  • Line 1: We import the numpy module.
  • Lines 4 to 5: We create the input arrays, myarray1 and myarray2 using the array() function.
  • Lines 8 to 9: We print the arrays myarray1 and myarray2.
  • Line 12: We implement the char.greater_equal() function on both arrays to check if the elements in myarray1 are greater than or equal to the elements in myarray2. We print the result to the console.

Free Resources