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)) |
chevron_right
filter_none
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)) |
chevron_right
filter_none
Output:
find of 'Aa' [15 6 1 1] find of 'Aa' [15 -1 -1 -1]
Recommended Posts:
- Reading Python File-Like Objects from C | Python
- Python | Convert list to Python array
- Python | Index of Non-Zero elements in Python list
- Important differences between Python 2.x and Python 3.x with examples
- Python | Merge Python key values to list
- Python | Set 4 (Dictionary, Keywords in Python)
- Python | Sort Python Dictionaries by Key or Value
- Python | Add Logging to Python Libraries
- Python | Add Logging to a Python Script
- Python | Visualizing O(n) using Python
- JavaScript vs Python : Can Python Overtop JavaScript by 2020?
- Use of min() and max() in Python
- zip() in Python
- set add() in python
- try and except in Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



