w3resource
NumPy Tutorial

NumPy: String operations routines

String operations routines

This module provides a set of vectorized string operations for arrays of type numpy.string_ or numpy.unicode_. All of them are based on the string methods in the Python standard library.

zfill(a, width)
String operations
Name Description Syntax
add() Return element-wise string concatenation for two arrays of str or unicode. numpy.core.defchararray.add(x1, x2)
multiply() Return (a * i), that is string multiple concatenation, element-wise. numpy.core.defchararray.multiply(a, i)
mod() Compute the bit-wise XOR of two arrays element-wise. numpy.core.defchararray.mod(a, values)
capitalize() Return a copy of a with only the first character of each element capitalized. numpy.core.defchararray.capitalize(a)
center() Return a copy of a with its elements centered in a string of length width. numpy.core.defchararray.center(a, width, fillchar=' ')
decode() Calls str.decode element-wise. decode(a[, encoding, errors])
encode() Calls str.encode element-wise. encode(a[, encoding, errors])
join() Return a string which is the concatenation of the strings in the sequence seq. join(sep, seq)
ljust() Return an array with the elements of a left-justified in a string of length width. ljust(a, width[, fillchar])
lower() Return an array with the elements converted to lowercase. lower(a)
lstrip() For each element in a, return a copy with the leading characters removed. lstrip(a[, chars])
partition() Partition each element in a around sep. partition(a, sep)
replace() For each element in a, return a copy of the string with all occurrences of substring old replaced by new. replace(a, old, new[, count])
rjust() Return an array with the elements of a right-justified in a string of length width. rjust(a, width[, fillchar])
rpartition() Partition (split) each element around the right-most separator. rpartition(a, sep)
rsplit() For each element in a, return a list of the words in the string, using sep as the delimiter string. rsplit(a[, sep, maxsplit])
rstrip() For each element in a, return a copy with the trailing characters removed. rstrip(a[, chars])
split() For each element in a, return a list of the words in the string, using sep as the delimiter string. split(a[, sep, maxsplit])
splitlines() For each element in a, return a list of the lines in the element, breaking at line boundaries. splitlines(a[, keepends])
strip() For each element in a, return a copy with the leading and trailing characters removed. strip(a[, chars])
swapcase() Return element-wise a copy of the string with uppercase characters converted to lowercase and vice versa. swapcase(a)
title() Return element-wise title cased version of string or unicode. replace(a, old, new[, count])
translate() 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. translate(a, table[, deletechars])
upper() Return an array with the elements converted to uppercase. upper(a)
zfill() Return the numeric string left-filled with zeros.
Comparison
Name Description Syntax
equal() Return (x1 == x2) element-wise.. numpy.core.defchararray.equal(x1, x2)
not_equal() Convert inputs to arrays with at least one dimension. atleast_1d(*arys)
greater_equal() Convert inputs to arrays with at least one dimension. atleast_1d(*arys)
less_equal() Convert inputs to arrays with at least one dimension. atleast_1d(*arys)
greater() Convert inputs to arrays with at least one dimension. atleast_1d(*arys)
less() Convert inputs to arrays with at least one dimension. atleast_1d(*arys)
String Information
Name Description Syntax
count() Returns an array with the number of non-overlapping occurrences of substring sub in the range [start, end]. numpy.core.defchararray.count(a, sub, start=0, end=None)
find() Return the lowest index in the string where substring sub is found. numpy.core.defchararray.find(a, sub, start=0, end=None)
index() Raises ValueError when the substring is not found. numpy.core.defchararray.index(a, sub, start=0, end=None)
isalpha() Returns true for each element if all characters in the string are alphabetic and there is at least one character, false otherwise. numpy.core.defchararray.isalpha(a)
isdecimal() Return True if there are only decimal characters in the element. numpy.core.defchararray.isdecimal(a)
isdigit() Returns true for each element if all characters in the string are digits and there is at least one character, false otherwise. numpy.core.defchararray.isdigit(a)
islower() Returns true for each element if all cased characters in the string are lowercase and there is at least one cased character, false otherwise. numpy.core.defchararray.islower(a)
isnumeric() Return True if there are only numeric characters in the element. numpy.core.defchararray.isnumeric(a)
isspace() Returns true for each element if there are only whitespace characters in the string and there is at least one character, false otherwise. numpy.core.defchararray.isspace(a)
istitle() Returns true for each element if the element is a titlecased string and there is at least one character, false otherwise. numpy.core.defchararray.istitle(a)
isupper() Returns true for each element if all cased characters in the string are uppercase and there is at least one character, false otherwise. numpy.core.defchararray.isupper(a)
rfind() Return the highest index in the string where substring sub is found, such that sub is contained within [start, end]. numpy.core.defchararray.rfind(a, sub, start=0, end=None)
rindex() Raises ValueError when the substring sub is not found. Calls str.rindex element-wise. numpy.core.defchararray.rindex(a, sub, start=0, end=None)
startswith() Returns a boolean array which is True where the string element in a starts with prefix, otherwise False. numpy.core.defchararray.startswith(a, prefix, start=0, end=None)
Convenience class
Name Description Syntax
chararray() Provides a convenient view on arrays of string and unicode values. class numpy.core.defchararray.chararray(shape, itemsize=1, unicode=False, buffer=None, offset=0, strides=None, order=None)

Previous: binary_repr()
Next: add()