Skip to main content
`Ctrl`+`K`

# Legacy fixed-width string functionality

Legacy

This submodule is considered legacy and will no longer receive updates. This could also mean it will be removed in future NumPy versions. The string operations in this module, as well as the `numpy.char.chararray` class, are planned to be deprecated in the future. Use `numpy.strings` instead.

The `numpy.char` module provides a set of vectorized string operations for arrays of type `numpy.str_` or `numpy.bytes_`. For example

The methods in this module are based on the methods in `string`

## String operations

`add` |
`multiply`(a, i) | Return (a * i), that is string multiple concatenation, element-wise.
`mod`(a, values) | Return (a % i), that is pre-Python 2.6 string formatting (interpolation), element-wise for a pair of array_likes of str or unicode.
`capitalize`(a) | Return a copy of `a` with only the first character of each element capitalized.
`center`(a, width[, fillchar]) | Return a copy of a with its elements centered in a string of length width.
`decode`(a[, encoding, errors]) | Calls `bytes.decode` element-wise.
`encode`(a[, encoding, errors]) | Calls `str.encode` element-wise.
`expandtabs`(a[, tabsize]) | Return a copy of each string element where all tab characters are replaced by one or more spaces.
`join`(sep, seq) | Return a string which is the concatenation of the strings in the sequence seq.
`ljust`(a, width[, fillchar]) | Return an array with the elements of a left-justified in a string of length width.
`lower`(a) | Return an array with the elements converted to lowercase.
`lstrip`(a[, chars]) | For each element in a, return a copy with the leading characters removed.
`partition`(a, sep) | Partition each element in a around sep.
`replace`(a, old, new[, count]) | For each element in `a`, return a copy of the string with occurrences of substring `old` replaced by `new`.
`rjust`(a, width[, fillchar]) | Return an array with the elements of a right-justified in a string of length width.
`rpartition`(a, sep) | Partition (split) each element around the right-most separator.
`rsplit`(a[, sep, maxsplit]) | For each element in a, return a list of the words in the string, using sep as the delimiter string.
`rstrip`(a[, chars]) | For each element in a, return a copy with the trailing characters removed.
`split`(a[, sep, maxsplit]) | For each element in a, return a list of the words in the string, using sep as the delimiter string.
`splitlines`(a[, keepends]) | For each element in a, return a list of the lines in the element, breaking at line boundaries.
`strip`(a[, chars]) | For each element in a, return a copy with the leading and trailing characters removed.
`swapcase`(a) | Return element-wise a copy of the string with uppercase characters converted to lowercase and vice versa.
`title`(a) | Return element-wise title cased version of string or unicode.
`translate`(a, table[, deletechars]) | For each element in a, return a copy of the string where all characters occurring in the optional argument deletechars are removed, and the remaining characters have been mapped through the given translation table.
`upper`(a) | Return an array with the elements converted to uppercase.
`zfill`(a, width) | Return the numeric string left-filled with zeros.

## Comparison

Unlike the standard numpy comparison operators, the ones in the char module strip trailing whitespace characters before performing the comparison.

`equal`(x1, x2) | Return (x1 == x2) element-wise.
`not_equal`(x1, x2) | Return (x1 != x2) element-wise.
`greater_equal`(x1, x2) | Return (x1 >= x2) element-wise.
`less_equal`(x1, x2) | Return (x1 <= x2) element-wise.
`greater`(x1, x2) | Return (x1 > x2) element-wise.
`less`(x1, x2) | Return (x1 < x2) element-wise.
`compare_chararrays`(a1, a2, cmp, rstrip) | Performs element-wise comparison of two string arrays using the comparison operator specified by cmp.

## String information

`count`(a, sub[, start, end]) | Returns an array with the number of non-overlapping occurrences of substring `sub` in the range [`start`, `end`).
`endswith`(a, suffix[, start, end]) | Returns a boolean array which is True where the string element in `a` ends with `suffix`, otherwise False.
`find`(a, sub[, start, end]) | For each element, return the lowest index in the string where substring `sub` is found, such that `sub` is contained in the range [`start`, `end`).
`index`(a, sub[, start, end]) | Like `find`, but raises `ValueError` when the substring is not found.
`isalpha` |
`isalnum` |
`isdecimal` |
`isdigit` |
`islower` |
`isnumeric` |
`isspace` |
`istitle` |
`isupper` |
`rfind`(a, sub[, start, end]) | For each element, return the highest index in the string where substring `sub` is found, such that `sub` is contained in the range [`start`, `end`).
`rindex`(a, sub[, start, end]) | Like `rfind`, but raises `ValueError` when the substring sub is not found.
`startswith`(a, prefix[, start, end]) | Returns a boolean array which is True where the string element in `a` starts with `prefix`, otherwise False.
`str_len` |

## Convenience class

`array`(obj[, itemsize, copy, unicode, order]) | Create a `chararray`.
`asarray`(obj[, itemsize, unicode, order]) | Convert the input to a `chararray`, copying the data only if necessary.
`chararray`(shape[, itemsize, unicode, ...]) | Provides a convenient view on arrays of string and unicode values.