numpy.char.compare_chararrays

char.compare_chararrays(a1, a2, cmp, rstrip)

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

Parameters
a1, a2array_like

Arrays to be compared.

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

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])