Thursday, December 18, 2025
HomeLanguagesnumpy.find() in Python

numpy.find() in Python

numpy.core.defchararray.find(arr, substring, start=0, end=None): Finds the lowest index of the sub-string in the specified range.

Parameters:
arr : array-like or string to be searched.
substring : substring to search for.
start, end : [int, optional] Range to search in.

Returns : An integer array with the lowest index of found sub-string.

Code #1:




# Python Program illustrating 
# numpy.char.find() method 
import numpy as np 
  
arr = ['vdsdsttetteteAAAa', 'AAAAAAAaattttds', 'AAaaxxxxtt', 'AAaaXDSDdscz']
  
print ("arr : ", arr)
  
print ("\nfind of 'tt'", np.char.find(arr, 'tt'))
print ("find of 'tt'", np.char.find(arr, 'tt', start = 0))
print ("find of 'tt'", np.char.find(arr, 'tt', start = 8))


Output:

arr :  ['vdsdsttetteteAAAa', 'AAAAAAAaattttds', 'AAaaxxxxtt', 'AAaaXDSDdscz']

find of 'tt' [ 5  9  8 -1]
find of 'tt' [ 5  9  8 -1]
find of 'tt' [ 8  9  8 -1]

 
Code #2:




# Python Program illustrating 
# numpy.char.find() method 
import numpy as np 
  
arr = ['vdsdsttetteteAAAa', 'AAAAAAAaattttds', 'AAaaxxxxtt', 'AAaaXDSDdscz']
  
  
print ("\nfind of 'Aa'", np.char.find(arr, 'Aa'))
print ("find of 'Aa'", np.char.find(arr, 'Aa', start = 8))


Output:

find of 'Aa' [15  6  1  1]
find of 'Aa' [15 -1 -1 -1]
RELATED ARTICLES

Most Popular

Dominic
32455 POSTS0 COMMENTS
Milvus
108 POSTS0 COMMENTS
Nango Kala
6823 POSTS0 COMMENTS
Nicole Veronica
11958 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12036 POSTS0 COMMENTS
Shaida Kate Naidoo
6958 POSTS0 COMMENTS
Ted Musemwa
7203 POSTS0 COMMENTS
Thapelo Manthata
6910 POSTS0 COMMENTS
Umr Jansen
6890 POSTS0 COMMENTS