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

Code explanation

  • Line 1: We import the numpy library.
  • Lines 4–5: We create the input arrays, myarray1 and myarray2, using the array() function.
  • Lines 8–9: We print the arrays myarray1 and myarray2.
  • Line 12: We implement the char.less_equal() function on both the arrays to check if the elements in myarray1 are less than or equal to the elements in myarray2. And then, we print the results to the console.

Free Resources