NumPy 字符串函数

2024 年 8 月 29 日 | 阅读 3 分钟

NumPy 包含以下用于处理 dtype 字符串数组的函数。

序号函数描述
1add()它用于连接对应的数组元素(字符串)。
2multiply()它返回指定字符串的多个副本,例如,如果字符串 'hello' 乘以 3,则返回字符串 'hello hello'。
3center()它返回字符串的副本,其中原始字符串以指定的填充字符填充在左侧和右侧。
4capitalize()它返回原始字符串的副本,其中原始字符串的第一个字母转换为大写。
5title()它返回字符串的标题大小写版本,即字符串中每个单词的第一个字母都转换为大写。
6lower()它返回字符串的副本,其中所有字母都转换为小写。
7upper()它返回字符串的副本,其中所有字母都转换为大写。
9split()它返回字符串中的单词列表。
9splitlines()它返回字符串中的行列表,在行边界处断开。
10strip()返回一个字符串副本,删除前导和尾随空格。
11join()它返回一个字符串,该字符串是给定序列中所有指定字符串的连接。
12replace()它通过将特定子字符串的所有出现替换为指定的子字符串来返回字符串的副本。
13decode()它用于使用指定的编解码器逐元素解码指定的字符串。
14encode()它用于逐元素编码解码后的字符串。

numpy.char.add() 方法示例

输出

Concatenating two string arrays:
['welcome to Javatpoint' 'Hi read python']

numpy.char.multiply() 方法示例

输出

Printing a string multiple times:
hello hello hello 

numpy.char.center() 方法示例

输出

Padding the string through left and right with the fill char *
*****Javatpoint*****

numpy.char.capitalize() 方法示例

输出

Capitalizing the string using capitalize()...
Welcome to javatpoint

numpy.char.title() 方法示例

输出

Converting string into title cased version...
Welcome To Javatpoint

numpy.char.lower() 方法示例

输出

Converting all the characters of the string into lowercase...
welcome to javatpoint

numpy.char.upper() 方法示例

输出

Converting all the characters of the string into uppercase...
WELCOME TO JAVATPOINT

numpy.char.split() 方法示例

输出

Splitting the String word by word..
['Welcome', 'To', 'Javatpoint']

numpy.char.splitlines() 方法示例

输出

Splitting the String line by line..
['Welcome', 'To', 'Javatpoint']

numpy.char.strip() 方法示例

输出

Original String:      welcome to javatpoint     
Removing the leading and trailing whitespaces from the string
welcome to javatpoint

numpy.char.join() 方法示例

输出

H:M

numpy.char.replace() 方法示例

输出

Original String: Welcome to Javatpoint
Modified String: www. Javatpoint

numpy.char.encode() 和 decode() 方法示例

输出

b'\xa6\x85\x93\x83\x96\x94\x85@\xa3\x96@\x91\x81\xa5\x81\xa3\x97\x96\x89\x95\xa3'
welcome to javatpoint

下一个主题NumPy 数学函数