numpy.char.replace #
- 字符。替换( a ,旧,新, count = None ) [来源] #
对于a中的每个元素,返回字符串的副本,其中所有出现的子字符串old都替换为new。
按元素调用str.replace 。
- 参数:
- 返回:
- 输出数组
str 或 unicode 的输出数组,具体取决于输入类型
也可以看看
例子
>>> a = np.array(["That is a mango", "Monkeys eat mangos"]) >>> np.char.replace(a, 'mango', 'banana') array(['That is a banana', 'Monkeys eat bananas'], dtype='<U19')
>>> a = np.array(["The dish is fresh", "This is it"]) >>> np.char.replace(a, 'is', 'was') array(['The dwash was fresh', 'Thwas was it'], dtype='<U19')