find() function - NumPy String Operations Last Updated : 29 Sep, 2025 Comments Improve Suggest changes Like Article Like Report 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. Python import numpy as np arr = np.array(["happy", "python", "numpy"]) print("Array:", arr) res = np.char.find(arr, "y") print("Result:", res) OutputArray: ['happy' 'python' 'numpy'] Result: [4 1 4] Explanation:"y" is found at index 4 in "happy",at index 5 in "python",and at index 4 in "numpy".Syntaxnumpy.char.find(arr, sub, start=0, end=None)Parameters:arr: array_like of str -> Input array of strings.sub: str -> Substring to search for.start: int, optional -> Starting index for search.end: int, optional -> Ending index for search.Return Value: ndarray of ints -> Positions of first occurrence of substring. Returns -1 if not found.ExamplesExample 1: This example searches for 'a' in the strings but only within indices 3 to 7. Python import numpy as np arr = np.array(['aAaAaA', 'aA', 'abBABba']) print("Array:", arr) res = np.char.find(arr, 'a', start=3, end=7) print("Result:", res) OutputArray: ['aAaAaA' 'aA' 'abBABba'] Result: [ 4 -1 6] Explanation:In "aAaAaA", 'a' occurs at index 4 (within range 3–7)."aA" has no 'a' in that range -> -1.In "abBABba", 'a' is found at index 6.Example 2: This example checks for the substring "num" inside each word. Python import numpy as np arr = np.array(["python", "numpy", "number", "fun"]) print("Array:", arr) res = np.char.find(arr, "num") print("Result:", res) OutputArray: ['python' 'numpy' 'number' 'fun'] Result: [-1 0 0 -1] Explanation:"num" is found at index 0 in "numpy" and "number".Not found in "python" or "fun", hence -1.Example 3: This example demonstrates that find() is case-sensitive. Python import numpy as np arr = np.array(["Apple", "banana", "Apricot"]) print("Array:", arr) res = np.char.find(arr, "a") print("Result:", res) OutputArray: ['Apple' 'banana' 'Apricot'] Result: [-1 1 -1] Explanation:'a' is not found in "Apple" (uppercase 'A' is different).Found at index 1 in "banana"."Apricot" has uppercase 'A', so lowercase 'a' is not matched. Create Quiz Comment J jana_sayantan Follow 0 Improve J jana_sayantan Follow 0 Improve Article Tags : Python Python-numpy Python numpy-String Operation Explore Python FundamentalsPython Introduction 2 min read Input and Output in Python 4 min read Python Variables 4 min read Python Operators 4 min read Python Keywords 2 min read Python Data Types 8 min read Conditional Statements in Python 3 min read Loops in Python - For, While and Nested Loops 5 min read Python Functions 5 min read Recursion in Python 4 min read Python Lambda Functions 5 min read Python Data StructuresPython String 5 min read Python Lists 4 min read Python Tuples 4 min read Python Dictionary 3 min read Python Sets 6 min read Python Arrays 7 min read List Comprehension in Python 4 min read Advanced PythonPython OOP Concepts 11 min read Python Exception Handling 5 min read File Handling in Python 4 min read Python Database Tutorial 4 min read Python MongoDB Tutorial 3 min read Python MySQL 9 min read Python Packages 10 min read Python Modules 3 min read Python DSA Libraries 15 min read List of Python GUI Library and Packages 3 min read Data Science with PythonNumPy Tutorial - Python Library 3 min read Pandas Tutorial 4 min read Matplotlib Tutorial 5 min read Python Seaborn Tutorial 3 min read StatsModel Library - Tutorial 3 min read Learning Model Building in Scikit-learn 6 min read TensorFlow Tutorial 2 min read PyTorch Tutorial 6 min read Web Development with PythonFlask Tutorial 8 min read Django Tutorial | Learn Django Framework 7 min read Django ORM - Inserting, Updating & Deleting Data 4 min read Templating With Jinja2 in Flask 6 min read Django Templates 5 min read Build a REST API using Flask - Python 3 min read Building a Simple API with Django REST Framework 3 min read Python PracticePython Quiz 1 min read Python Coding Practice 1 min read Python Interview Questions and Answers 15+ min read Like