String functionality#
Thenumpy.strings module provides a set of universal functions operatingon arrays of typenumpy.str_ ornumpy.bytes_.For example,
>>>np.strings.add(["num","doc"],["py","umentation"])array(['numpy', 'documentation'], dtype='<U13')
These universal functions are also used innumpy.char, which providesthenumpy.char.chararray array subclass, in order for those routinesto get the performance benefits as well.
Note
Prior to NumPy 2.0, all string functionality was innumpy.char, whichonly operated on fixed-width strings. That module will not be gettingupdates and will be deprecated at some point in the future.
String operations#
| Add arguments element-wise. |
| Return a copy ofa with its elements centered in a string of lengthwidth. |
| Return a copy of |
| Calls |
| Calls |
| Return a copy of each string element where all tab characters are replaced by one or more spaces. |
| Return an array with the elements ofa left-justified in a string of lengthwidth. |
| Return an array with the elements converted to lowercase. |
| For each element ina, return a copy with the leading characters removed. |
| Return (a % i), that is pre-Python 2.6 string formatting (interpolation), element-wise for a pair of array_likes of str or unicode. |
| Return (a * i), that is string multiple concatenation, element-wise. |
| Partition each element in |
| For each element in |
| Return an array with the elements ofa right-justified in a string of lengthwidth. |
| Partition (split) each element around the right-most separator. |
| For each element ina, return a copy with the trailing characters removed. |
| Slice the strings ina by slices specified bystart,stop,step. |
| For each element ina, return a copy with the leading and trailing characters removed. |
| Return element-wise a copy of the string with uppercase characters converted to lowercase and vice versa. |
| Return element-wise title cased version of string or unicode. |
| For each element ina, return a copy of the string where all characters occurring in the optional argumentdeletechars are removed, and the remaining characters have been mapped through the given translation table. |
| Return an array with the elements converted to uppercase. |
| Return the numeric string left-filled with zeros. |
Comparison#
Thenumpy.strings module also exports the comparison universal functionsthat can now operate on string arrays as well.
| Return (x1 == x2) element-wise. |
| Return (x1 != x2) element-wise. |
| Return the truth value of (x1 >= x2) element-wise. |
| Return the truth value of (x1 <= x2) element-wise. |
| Return the truth value of (x1 > x2) element-wise. |
| Return the truth value of (x1 < x2) element-wise. |
String information#
| Returns an array with the number of non-overlapping occurrences of substring |
| Returns a boolean array which isTrue where the string element in |
| For each element, return the lowest index in the string where substring |
| Like |
| Returns true for each element if all characters in the string are alphanumeric and there is at least one character, false otherwise. |
| Returns true for each element if all characters in the data interpreted as a string are alphabetic and there is at least one character, false otherwise. |
| For each element, return True if there are only decimal characters in the element. |
| Returns true for each element if all characters in the string are digits and there is at least one character, false otherwise. |
| Returns true for each element if all cased characters in the string are lowercase and there is at least one cased character, false otherwise. |
| For each element, return True if there are only numeric characters in the element. |
| Returns true for each element if there are only whitespace characters in the string and there is at least one character, false otherwise. |
| Returns true for each element if the element is a titlecased string and there is at least one character, false otherwise. |
| Return true for each element if all cased characters in the string are uppercase and there is at least one character, false otherwise. |
| For each element, return the highest index in the string where substring |
| Like |
| Returns a boolean array which isTrue where the string element in |
| Returns the length of each element. |