numpy.char.strip
-
numpy.char.strip(a, chars=None)
-
For each element in
a
, return a copy with the leading and trailing characters removed.Calls
str.strip
element-wise.- Parameters
-
-
aarray-like of str or unicode
-
charsstr or unicode, optional
-
The
chars
argument is a string specifying the set of characters to be removed. If omitted or None, thechars
argument defaults to removing whitespace. Thechars
argument is not a prefix or suffix; rather, all combinations of its values are stripped.
-
- Returns
-
-
outndarray
-
Output array of str or unicode, depending on input type
-
See also
Examples
>>> c = np.array(['aAaAaA', ' aA ', 'abBABba']) >>> c array(['aAaAaA', ' aA ', 'abBABba'], dtype='<U7') >>> np.char.strip(c) array(['aAaAaA', 'aA', 'abBABba'], dtype='<U7') >>> np.char.strip(c, 'a') # 'a' unstripped from c[1] because whitespace leads array(['AaAaA', ' aA ', 'bBABb'], dtype='<U7') >>> np.char.strip(c, 'A') # 'A' unstripped from c[1] because (unprinted) ws trails array(['aAaAa', ' aA ', 'abBABba'], dtype='<U7')
© 2005–2020 NumPy Developers
Licensed under the 3-clause BSD License.
https://numpy.org/doc/1.19/reference/generated/numpy.char.strip.html