numpy.strings.index — NumPy v2.6.dev0 Manual

strings.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_ dtypesubarray-like, with StringDType, bytes_, or str_ dtypestart, endarray_like, with any integer dtype, optionalReturns:outndarrayOutput array of ints.

Examples

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