Numpy 字符串函数
一下函数用于对dtype 为 numpy.string_ 或 numpy.unicode_ 的数组执行向量话字符串操作。 他们基于 Python 内置库中标准的字符串函数。
这些函数在字符串数组类(numpy.char)中定义。
| 函数 | 描述 |
| add() | 对两个数组的逐个字符串元素进行连接 |
| multiply() | 返回按元素多重连接后的字符串 |
| center() | 居中字符串 |
|
capitalize() |
将字符串第一个字母转换为大写 |
| title() | 将字符串的每个单词的第一个字母转换为大写 |
| lower() | 数组元素转换为小写 |
| upper() | 数组元素转换为大写 |
| split() | 指定分隔符对字符串进行分隔,并返回数组列表 |
| splitlines() | 返回元素中的行元素,以换行符分隔 |
| strip() | 移除元素开头或者结尾处对的特定字符 |
| join() | 通过指定的分隔符来连接数组中的元素 |
| replace() | 使用新字符传替换字符串中所有的子字符串 |
| decode() |
数组元素依次调用str.decode |
| encode() | 数组元素依次调用str.encdoe |
numpy.char.add()
numpy.char.add() 函数依次对两个数组元素进行字符串连接。
import numpy as np print('连接两个字符串:') print(np.char.add(['hello'],['xyz'])) print('\n') print('连接提示:') print(np.char.add(['hello', 'hi'],['abc', 'xyz'])) 输出结果为: 连接两个字符串: ['hello xyz'] 连接示例: ['hello abc' 'hi xyz']
浙公网安备 33010602011771号