numpy.char.index

char.index(a, sub, start=0, end=None)[source]

Like find, but raises ValueError when the substring is not found.

Parameters:
aarray-like, with StringDType, bytes_, or str_ dtype
subarray-like, with StringDType, bytes_, or str_ dtype
start, endarray_like, with any integer dtype, optional
Returns:
outndarray

Output array of ints.

See also

find, str.index

Examples

>>> a = np.array(["Computer Science"])
>>> np.strings.index(a, "Science", start=0, end=None)
array([9])

© 2005–2024 NumPy Developers
Licensed under the 3-clause BSD License.
https://numpy.org/doc/2.0/reference/generated/numpy.char.index.html