bundles / numpy 2.4.4 / numpy / char / compare_chararrays
built-in
numpy.char:compare_chararrays
Signature
built-in
compare_chararrays ( a1 , a2 , cmp , rstrip ) Summary
Performs element-wise comparison of two string arrays using the comparison operator specified by cmp.
Parameters
a1, a2: array_likeArrays to be compared.
cmp: {"<", "<=", "==", ">=", ">", "!="}Type of comparison.
rstrip: boolIf True, the spaces at the end of strings are removed before the comparison.
Returns
out: ndarrayThe output array of type numpy.bool with the same shape as
a1anda2.
Raises
: ValueErrorIf
cmpis not valid.: TypeErrorIf at least one of
a1ora2is a non-string array
Examples
import numpy as np a = np.array(["a", "b", "cde"]) b = np.array(["a", "a", "dec"]) np.char.compare_chararrays(a, b, ">", True)✓
Aliases
-
numpy.char.compare_chararrays