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')