![]() |
VOOZH | about |
The numpy.char.find() function is used to locate first occurrence of a substring within each string element of a NumPy array. This is helpful when working with string arrays and searching for patterns within them.
For Example: This example shows how to find the position of "y" in each string of the array.
Array: ['happy' 'python' 'numpy'] Result: [4 1 4]
Explanation:
numpy.char.find(arr, sub, start=0, end=None)
Parameters:
Return Value: ndarray of ints -> Positions of first occurrence of substring. Returns -1 if not found.
Example 1: This example searches for 'a' in the strings but only within indices 3 to 7.
Array: ['aAaAaA' 'aA' 'abBABba'] Result: [ 4 -1 6]
Explanation:
Example 2: This example checks for the substring "num" inside each word.
Array: ['python' 'numpy' 'number' 'fun'] Result: [-1 0 0 -1]
Explanation:
Example 3: This example demonstrates that find() is case-sensitive.
Array: ['Apple' 'banana' 'Apricot'] Result: [-1 1 -1]
Explanation: