numpy.char.compare_chararrays

numpy.char.compare_chararrays(a, b, cmp_op, rstrip)

Performs element-wise comparison of two string arrays using the comparison operator specified by cmp_op.

Parameters
a, barray_like

Arrays to be compared.

cmp_op{“<”, “<=”, “==”, “>=”, “>”, “!=”}

Type of comparison.

rstripBoolean

If True, the spaces at the end of Strings are removed before the comparison.

Returns
outndarray

The output array of type Boolean with the same shape as a and b.

Raises
ValueError

If cmp_op is not valid.

TypeError

If at least one of a or b is a non-string array

Examples

>>> a = np.array(["a", "b", "cde"])
>>> b = np.array(["a", "a", "dec"])
>>> np.compare_chararrays(a, b, ">", True)
array([False,  True, False])

© 2005–2020 NumPy Developers
Licensed under the 3-clause BSD License.
https://numpy.org/doc/1.19/reference/generated/numpy.char.compare_chararrays.html