numpy.strings.replace#

strings.replace(a,old,new,count=-1)[source]#

For each element ina, return a copy of the string withoccurrences of substringold replaced bynew.

Parameters:
aarray_like, withbytes_ orstr_ dtype
old, newarray_like, withbytes_ orstr_ dtype
countarray_like, withint_ dtype

If the optional argumentcount is given, only the firstcount occurrences are replaced.

Returns:
outndarray

Output array ofStringDType,bytes_ orstr_ dtype,depending on input types

See also

str.replace

Examples

>>>importnumpyasnp>>>a=np.array(["That is a mango","Monkeys eat mangos"])>>>np.strings.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.strings.replace(a,'is','was')array(['The dwash was fresh', 'Thwas was it'], dtype='<U19')
On this page