This is a pre-release version (latest). Go to latest (2.4.4)
{ } Raw JSON

bundles / numpy latest / numpy / strings / replace

_ArrayFunctionDispatcher

numpy.strings:replace

source: build-install/usr/lib/python3.14/site-packages/numpy/_core/strings.py :1289

Signature

def   replace ( a old new count = -1 )

Summary

For each element in a, return a copy of the string with occurrences of substring old replaced by new.

Parameters

a : array_like, with ``bytes_`` or ``str_`` dtype
old, new : array_like, with ``bytes_`` or ``str_`` dtype
count : array_like, with ``int_`` dtype

If the optional argument count is given, only the first count occurrences are replaced.

Returns

out : ndarray

Output array of StringDType, bytes_ or str_ dtype, depending on input types

Examples

import numpy as np
a = np.array(["That is a mango", "Monkeys eat mangos"])
np.strings.replace(a, 'mango', 'banana')
a = np.array(["The dish is fresh", "This is it"])
np.strings.replace(a, 'is', 'was')

See also

str.replace

Aliases

  • numpy.char.replace