本文整理匯總了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)