本文整理汇总了Python中numpy.char方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.char方法的具体用法?Python numpy.char怎么用?Python numpy.char使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy
的用法示例。
在下文中一共展示了numpy.char方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: capitalize
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import char [as 别名]
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')
示例2: lower
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import char [as 别名]
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')
示例3: swapcase
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import char [as 别名]
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')
示例4: title
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import char [as 别名]
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')
示例5: upper
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import char [as 别名]
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')
示例6: count
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import char [as 别名]
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)
示例7: decode
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import char [as 别名]
def decode(self, encoding=None, errors=None):
"""
Calls `str.decode` element-wise.
See also
--------
char.decode
"""
return decode(self, encoding, errors)
示例8: encode
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import char [as 别名]
def encode(self, encoding=None, errors=None):
"""
Calls `str.encode` element-wise.
See also
--------
char.encode
"""
return encode(self, encoding, errors)
示例9: endswith
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import char [as 别名]
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)
示例10: find
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import char [as 别名]
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)
示例11: index
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import char [as 别名]
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)
示例12: isalnum
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import char [as 别名]
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)
示例13: isalpha
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import char [as 别名]
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)
示例14: isdigit
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import char [as 别名]
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)
示例15: isspace
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import char [as 别名]
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)