numpy.strings.translate#
- strings.translate(a, table, deletechars=None)[源]#
对于 a 中的每个元素,返回字符串的副本,其中所有在可选参数 deletechars 中出现的字符都将被移除,剩余字符将通过给定的转换表进行映射。
逐元素调用
str.translate
。- 参数:
- a类数组,其 np.bytes_ 或 np.str_ 数据类型
- table长度为 256 的字符串
- deletechars字符串
- 返回:
- outndarray
输出为字符串或 Unicode 数组,取决于输入类型
另请参阅
示例
>>> import numpy as np >>> a = np.array(['a1b c', '1bca', 'bca1']) >>> table = a[0].maketrans('abc', '123') >>> deletechars = ' ' >>> np.char.translate(a, table, deletechars) array(['112 3', '1231', '2311'], dtype='<U5')