Python numpy.char() Examples
The following are 30 code examples for showing how to use numpy.char(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.
You may check out the related API usage on the sidebar.
You may also want to check out all available functions/classes of the module
numpy
, or try the search function
.
Example 1
Project: recruit Author: Frank-qlu File: defchararray.py License: Apache License 2.0 | 5 votes |
def capitalize(a): """ Return a copy of `a` with only the first character of each element capitalized. Calls `str.capitalize` element-wise. For 8-bit strings, this method is locale-dependent. Parameters ---------- a : array_like of str or unicode Input array of strings to capitalize. Returns ------- out : ndarray Output array of str or unicode, depending on input types See also -------- str.capitalize Examples -------- >>> c = np.array(['a1b2','1b2a','b2a1','2a1b'],'S4'); c array(['a1b2', '1b2a', 'b2a1', '2a1b'], dtype='|S4') >>> np.char.capitalize(c) array(['A1b2', '1b2a', 'B2a1', '2a1b'], dtype='|S4') """ a_arr = numpy.asarray(a) return _vec_string(a_arr, a_arr.dtype, 'capitalize')
Example 2
Project: recruit Author: Frank-qlu File: defchararray.py License: Apache License 2.0 | 5 votes |
def lower(a): """ Return an array with the elements converted to lowercase. Call `str.lower` element-wise. For 8-bit strings, this method is locale-dependent. Parameters ---------- a : array_like, {str, unicode} Input array. Returns ------- out : ndarray, {str, unicode} Output array of str or unicode, depending on input type See also -------- str.lower Examples -------- >>> c = np.array(['A1B C', '1BCA', 'BCA1']); c array(['A1B C', '1BCA', 'BCA1'], dtype='|S5') >>> np.char.lower(c) array(['a1b c', '1bca', 'bca1'], dtype='|S5') """ a_arr = numpy.asarray(a) return _vec_string(a_arr, a_arr.dtype, 'lower')
Example 3
Project: recruit Author: Frank-qlu File: defchararray.py License: Apache License 2.0 | 5 votes |
def swapcase(a): """ Return element-wise a copy of the string with uppercase characters converted to lowercase and vice versa. Calls `str.swapcase` element-wise. For 8-bit strings, this method is locale-dependent. Parameters ---------- a : array_like, {str, unicode} Input array. Returns ------- out : ndarray, {str, unicode} Output array of str or unicode, depending on input type See also -------- str.swapcase Examples -------- >>> c=np.array(['a1B c','1b Ca','b Ca1','cA1b'],'S5'); c array(['a1B c', '1b Ca', 'b Ca1', 'cA1b'], dtype='|S5') >>> np.char.swapcase(c) array(['A1b C', '1B cA', 'B cA1', 'Ca1B'], dtype='|S5') """ a_arr = numpy.asarray(a) return _vec_string(a_arr, a_arr.dtype, 'swapcase')
Example 4
Project: recruit Author: Frank-qlu File: defchararray.py License: Apache License 2.0 | 5 votes |
def title(a): """ Return element-wise title cased version of string or unicode. Title case words start with uppercase characters, all remaining cased characters are lowercase. Calls `str.title` element-wise. For 8-bit strings, this method is locale-dependent. Parameters ---------- a : array_like, {str, unicode} Input array. Returns ------- out : ndarray Output array of str or unicode, depending on input type See also -------- str.title Examples -------- >>> c=np.array(['a1b c','1b ca','b ca1','ca1b'],'S5'); c array(['a1b c', '1b ca', 'b ca1', 'ca1b'], dtype='|S5') >>> np.char.title(c) array(['A1B C', '1B Ca', 'B Ca1', 'Ca1B'], dtype='|S5') """ a_arr = numpy.asarray(a) return _vec_string(a_arr, a_arr.dtype, 'title')
Example 5
Project: recruit Author: Frank-qlu File: defchararray.py License: Apache License 2.0 | 5 votes |
def upper(a): """ Return an array with the elements converted to uppercase. Calls `str.upper` element-wise. For 8-bit strings, this method is locale-dependent. Parameters ---------- a : array_like, {str, unicode} Input array. Returns ------- out : ndarray, {str, unicode} Output array of str or unicode, depending on input type See also -------- str.upper Examples -------- >>> c = np.array(['a1b c', '1bca', 'bca1']); c array(['a1b c', '1bca', 'bca1'], dtype='|S5') >>> np.char.upper(c) array(['A1B C', '1BCA', 'BCA1'], dtype='|S5') """ a_arr = numpy.asarray(a) return _vec_string(a_arr, a_arr.dtype, 'upper')
Example 6
Project: recruit Author: Frank-qlu File: defchararray.py License: Apache License 2.0 | 5 votes |
def capitalize(self): """ Return a copy of `self` with only the first character of each element capitalized. See also -------- char.capitalize """ return asarray(capitalize(self))
Example 7
Project: recruit Author: Frank-qlu File: defchararray.py License: Apache License 2.0 | 5 votes |
def count(self, sub, start=0, end=None): """ Returns an array with the number of non-overlapping occurrences of substring `sub` in the range [`start`, `end`]. See also -------- char.count """ return count(self, sub, start, end)
Example 8
Project: recruit Author: Frank-qlu File: defchararray.py License: Apache License 2.0 | 5 votes |
def decode(self, encoding=None, errors=None): """ Calls `str.decode` element-wise. See also -------- char.decode """ return decode(self, encoding, errors)
Example 9
Project: recruit Author: Frank-qlu File: defchararray.py License: Apache License 2.0 | 5 votes |
def encode(self, encoding=None, errors=None): """ Calls `str.encode` element-wise. See also -------- char.encode """ return encode(self, encoding, errors)
Example 10
Project: recruit Author: Frank-qlu File: defchararray.py License: Apache License 2.0 | 5 votes |
def endswith(self, suffix, start=0, end=None): """ Returns a boolean array which is `True` where the string element in `self` ends with `suffix`, otherwise `False`. See also -------- char.endswith """ return endswith(self, suffix, start, end)
Example 11
Project: recruit Author: Frank-qlu File: defchararray.py License: Apache License 2.0 | 5 votes |
def find(self, sub, start=0, end=None): """ For each element, return the lowest index in the string where substring `sub` is found. See also -------- char.find """ return find(self, sub, start, end)
Example 12
Project: recruit Author: Frank-qlu File: defchararray.py License: Apache License 2.0 | 5 votes |
def index(self, sub, start=0, end=None): """ Like `find`, but raises `ValueError` when the substring is not found. See also -------- char.index """ return index(self, sub, start, end)
Example 13
Project: recruit Author: Frank-qlu File: defchararray.py License: Apache License 2.0 | 5 votes |
def isalnum(self): """ Returns true for each element if all characters in the string are alphanumeric and there is at least one character, false otherwise. See also -------- char.isalnum """ return isalnum(self)
Example 14
Project: recruit Author: Frank-qlu File: defchararray.py License: Apache License 2.0 | 5 votes |
def isalpha(self): """ Returns true for each element if all characters in the string are alphabetic and there is at least one character, false otherwise. See also -------- char.isalpha """ return isalpha(self)
Example 15
Project: recruit Author: Frank-qlu File: defchararray.py License: Apache License 2.0 | 5 votes |
def isdigit(self): """ Returns true for each element if all characters in the string are digits and there is at least one character, false otherwise. See also -------- char.isdigit """ return isdigit(self)
Example 16
Project: recruit Author: Frank-qlu File: defchararray.py License: Apache License 2.0 | 5 votes |
def isspace(self): """ Returns true for each element if there are only whitespace characters in the string and there is at least one character, false otherwise. See also -------- char.isspace """ return isspace(self)
Example 17
Project: recruit Author: Frank-qlu File: defchararray.py License: Apache License 2.0 | 5 votes |
def istitle(self): """ Returns true for each element if the element is a titlecased string and there is at least one character, false otherwise. See also -------- char.istitle """ return istitle(self)
Example 18
Project: recruit Author: Frank-qlu File: defchararray.py License: Apache License 2.0 | 5 votes |
def isupper(self): """ Returns true for each element if all cased characters in the string are uppercase and there is at least one character, false otherwise. See also -------- char.isupper """ return isupper(self)
Example 19
Project: recruit Author: Frank-qlu File: defchararray.py License: Apache License 2.0 | 5 votes |
def join(self, seq): """ Return a string which is the concatenation of the strings in the sequence `seq`. See also -------- char.join """ return join(self, seq)
Example 20
Project: recruit Author: Frank-qlu File: defchararray.py License: Apache License 2.0 | 5 votes |
def ljust(self, width, fillchar=' '): """ Return an array with the elements of `self` left-justified in a string of length `width`. See also -------- char.ljust """ return asarray(ljust(self, width, fillchar))
Example 21
Project: recruit Author: Frank-qlu File: defchararray.py License: Apache License 2.0 | 5 votes |
def lstrip(self, chars=None): """ For each element in `self`, return a copy with the leading characters removed. See also -------- char.lstrip """ return asarray(lstrip(self, chars))
Example 22
Project: recruit Author: Frank-qlu File: defchararray.py License: Apache License 2.0 | 5 votes |
def replace(self, old, new, count=None): """ For each element in `self`, return a copy of the string with all occurrences of substring `old` replaced by `new`. See also -------- char.replace """ return asarray(replace(self, old, new, count))
Example 23
Project: recruit Author: Frank-qlu File: defchararray.py License: Apache License 2.0 | 5 votes |
def rfind(self, sub, start=0, end=None): """ For each element in `self`, return the highest index in the string where substring `sub` is found, such that `sub` is contained within [`start`, `end`]. See also -------- char.rfind """ return rfind(self, sub, start, end)
Example 24
Project: recruit Author: Frank-qlu File: defchararray.py License: Apache License 2.0 | 5 votes |
def rindex(self, sub, start=0, end=None): """ Like `rfind`, but raises `ValueError` when the substring `sub` is not found. See also -------- char.rindex """ return rindex(self, sub, start, end)
Example 25
Project: recruit Author: Frank-qlu File: defchararray.py License: Apache License 2.0 | 5 votes |
def rjust(self, width, fillchar=' '): """ Return an array with the elements of `self` right-justified in a string of length `width`. See also -------- char.rjust """ return asarray(rjust(self, width, fillchar))
Example 26
Project: recruit Author: Frank-qlu File: defchararray.py License: Apache License 2.0 | 5 votes |
def rstrip(self, chars=None): """ For each element in `self`, return a copy with the trailing characters removed. See also -------- char.rstrip """ return asarray(rstrip(self, chars))
Example 27
Project: recruit Author: Frank-qlu File: defchararray.py License: Apache License 2.0 | 5 votes |
def split(self, sep=None, maxsplit=None): """ For each element in `self`, return a list of the words in the string, using `sep` as the delimiter string. See also -------- char.split """ return split(self, sep, maxsplit)
Example 28
Project: recruit Author: Frank-qlu File: defchararray.py License: Apache License 2.0 | 5 votes |
def splitlines(self, keepends=None): """ For each element in `self`, return a list of the lines in the element, breaking at line boundaries. See also -------- char.splitlines """ return splitlines(self, keepends)
Example 29
Project: recruit Author: Frank-qlu File: defchararray.py License: Apache License 2.0 | 5 votes |
def startswith(self, prefix, start=0, end=None): """ Returns a boolean array which is `True` where the string element in `self` starts with `prefix`, otherwise `False`. See also -------- char.startswith """ return startswith(self, prefix, start, end)
Example 30
Project: recruit Author: Frank-qlu File: defchararray.py License: Apache License 2.0 | 5 votes |
def strip(self, chars=None): """ For each element in `self`, return a copy with the leading and trailing characters removed. See also -------- char.strip """ return asarray(strip(self, chars))