Numpy - String Functions & Operations Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report NumPy String functions belong to the numpy.char module and are designed to perform element-wise operations on arrays. These functions can help to handle and manipulate string data efficiently.Table of ContentString OperationsString Information String Comparison In this article, we’ll explore the various string functions provided by NumPy along with their examples. String Operationsnumpy.lower(): This function returns the lowercase string from the given string. It converts all uppercase characters to lowercase. If no uppercase characters exist, it returns the original string. Python import numpy as np # converting to lowercase print(np.char.lower(['GEEKS', 'FOR'])) # converting to lowercase print(np.char.lower('GEEKS')) Output['geeks' 'for'] geeks numpy.split() : This function returns a list of strings after breaking the given string by the specified separator. Python import numpy as np # splitting a string print(np.char.split('geeks for geeks')) # splitting a string print(np.char.split('geeks, for, geeks', sep = ',')) Output['geeks', 'for', 'geeks'] ['geeks', ' for', ' geeks'] numpy.join() : This function is a string method and returns a string in which the elements of sequence have been joined by str separator. Python import numpy as np # splitting a string print(np.char.join('-', 'geeks')) # splitting a string print(np.char.join(['-', ':'], ['geeks', 'for'])) Outputg-e-e-k-s ['g-e-e-k-s' 'f:o:r'] FUNCTIONDESCRIPTIONnumpy.strip()It is used to remove all the leading and trailing spaces from a string.numpy.capitalize()It converts the first character of a string to capital (uppercase) letter. If the string has its first character as capital, then it returns the original string.numpy.center()It creates and returns a new string which is padded with the specified character..numpy.decode()It is used to convert from one encoding scheme, in which argument string is encoded to the desired encoding scheme.numpy.encode()Returns the string in the encoded formnumpy.ljust()Return an array with the elements of a left-justified in a string of length width.numpy.rjust()For each element in a, return a copy with the leading characters removed.numpy.strip()For each element in a, return a copy with the leading and trailing characters removed.numpy.lstrip()Convert angles from degrees to radians.numpy.rstrip()For each element in a, return a copy with the trailing characters removed.numpy.partition()Partition each element in a around sep.numpy.rpartitionPartition (split) each element around the right-most separator.numpy.rsplit()For each element in a, return a list of the words in the string, using sep as the delimiter string.numpy.title()It is used to convert the first character in each word to Uppercase and remaining characters to Lowercase in string and returns new string.numpy.upper()Returns the uppercased string from the given string. It converts all lowercase characters to uppercase.If no lowercase characters exist, it returns the original string.String Information numpy.count() : This function returns the number of occurrences of a substring in the given string. Python import numpy as np a=np.array(['geeks', 'for', 'geeks']) # counting a substring print(np.char.count(a,'geek')) # counting a substring print(np.char.count(a, 'fo')) Output[1 0 1] [0 1 0] numpy.rfind() : This function returns the highest index of the substring if found in given string. If not found then it returns -1. Python import numpy as np a=np.array(['geeks', 'for', 'geeks']) # counting a substring print(np.char.rfind(a,'geek')) # counting a substring print(np.char.rfind(a, 'fo')) Output[ 0 -1 0] [-1 0 -1] numpy.isnumeric() : This function returns “True” if all characters in the string are numeric characters, Otherwise, It returns “False”. Python import numpy as np # counting a substring print(np.char.isnumeric('geeks')) # counting a substring print(np.char.isnumeric('12geeks')) OutputFalse False FUNCTIONDESCRIPTIONnumpy.find()It returns the lowest index of the substring if it is found in given string. If its is not found then it returns -1.numpy.index()It returns the position of the first occurrence of substring in a stringnumpy.isalpha()It returns “True” if all characters in the string are alphabets, Otherwise, It returns “False”.numpy.isdecimal()It returns true if all characters in a string are decimal. If all characters are not decimal then it returns false.numpy.isdigit()It returns “True” if all characters in the string are digits, Otherwise, It returns “False”.numpy.islower()It returns “True” if all characters in the string are lowercase, Otherwise, It returns “False”.numpy.isspace()Returns true for each element if there are only whitespace characters in the string and there is at least one character, false otherwise.numpy.istitle()Returns true for each element if the element is a titlecased string and there is at least one character, false otherwise.numpy.isupper()Returns true for each element if all cased characters in the string are uppercase and there is at least one character, false otherwise.numpy.rindex()Returns the highest index of the substring inside the string if substring is found. Otherwise it raises an exception.numpy.startswith()Returns True if a string starts with the given prefix otherwise returns False.String Comparison numpy.equal(): This function checks for string1 == string2 elementwise. Python import numpy as np # using equal() method a=np.char.equal('geeks','for') print(a) OutputFalse numpy.not_equal(): This function checks whether two string is unequal or not. Python import numpy as np # Comparing a string element-wise using not_equal() method a = np.char.not_equal('geeks', 'for') print(a) OutputTrue numpy.greater(): This function checks whether string1 is greater than string2 or not. Python import numpy as np # comparing a string elementwise a=np.char.greater('geeks','for') print(a) OutputTrue FUNCTIONDESCRIPTIONnumpy.greater_equal()It checks whether string1 >= string2 or not.numpy.less_equal()It checks whether string1 is <= string2 or not.numpy.less()It check whether string1 is lesser than string2 or not.Convenience classarray: Creates a new NumPy array from a list or similar data structure. Python import numpy as np arr = np.array([1, 2, 3, 4]) # Creating a NumPy array print(arr) chararray: Creates a NumPy array specialized for handling string operations. Python import numpy as np char_arr = np.chararray((2, 3)) # Creating a 2x3 character array char_arr[:] = 'Hello' # Assigning string values print(char_arr) asarray: Converts input data into a NumPy array, avoiding unnecessary copying if already an array. Python import numpy as np lst = [1, 2, 3, 4] arr = np.asarray(lst) # Converting list to NumPy array print(arr) FUNCTIONSDESCRIPTIONchararrayNumPy array for string operations, providing vectorized string processing capabilities.arrayCreates a NumPy array from input dataasarrayConverts input data into a NumPy array without copying Comment More info T tarunsarawgi_gfg Follow Improve Article Tags : Numpy Python-numpy Explore NumPy Tutorial - Python Library 3 min read IntroductionNumPy Introduction 7 min read Python NumPy 6 min read NumPy Array in Python 2 min read Basics of NumPy Arrays 4 min read Numpy - ndarray 3 min read Data type Object (dtype) in NumPy Python 3 min read Creating NumPy ArrayNumpy - Array Creation 5 min read numpy.arange() in Python 2 min read numpy.zeros() in Python 2 min read NumPy - Create array filled with all ones 2 min read NumPy - linspace() Function 2 min read numpy.eye() in Python 2 min read Creating a one-dimensional NumPy array 2 min read How to create an empty and a full NumPy array? 2 min read Create a Numpy array filled with all zeros - Python 2 min read How to generate 2-D Gaussian array using NumPy? 2 min read How to create a vector in Python using NumPy 4 min read Python - Numpy fromrecords() method 2 min read NumPy Array ManipulationNumPy Copy and View of Array 4 min read How to Copy NumPy array into another array? 2 min read Appending values at the end of an NumPy array 4 min read How to swap columns of a given NumPy array? 4 min read Insert a new axis within a NumPy array 4 min read numpy.hstack() in Python 2 min read numpy.vstack() in python 2 min read Joining NumPy Array 3 min read Combining a one and a two-dimensional NumPy Array 2 min read Numpy np.ma.concatenate() method-Python 2 min read Numpy dstack() method-Python 2 min read Splitting Arrays in NumPy 6 min read How to compare two NumPy arrays? 2 min read Find the union of two NumPy arrays 2 min read Find unique rows in a NumPy array 3 min read Numpy np.unique() method-Python 2 min read numpy.trim_zeros() in Python 2 min read Matrix in NumPyMatrix manipulation in Python 4 min read numpy matrix operations | empty() function 1 min read numpy matrix operations | zeros() function 2 min read numpy matrix operations | ones() function 2 min read numpy matrix operations | eye() function 2 min read numpy matrix operations | identity() function 1 min read Adding and Subtracting Matrices in Python 4 min read Matrix Multiplication in NumPy 2 min read Numpy ndarray.dot() function | Python 2 min read NumPy | Vector Multiplication 4 min read How to calculate dot product of two vectors in Python? 3 min read Multiplication of two Matrices in Single line using Numpy in Python 3 min read Python | Numpy np.eigvals() method 1 min read How to Calculate the determinant of a matrix using NumPy? 2 min read Python | Numpy matrix.transpose() 3 min read Python | Numpy matrix.var() 1 min read Compute the inverse of a matrix using NumPy 2 min read Operations on NumPy ArrayNumpy | Binary Operations 8 min read Numpy | Mathematical Function 9 min read Numpy - String Functions & Operations 5 min read Reshaping NumPy ArrayReshape NumPy Array 5 min read Python | Numpy matrix.resize() 1 min read Python | Numpy matrix.reshape() 1 min read NumPy Array Shape 2 min read Change the dimension of a NumPy array 3 min read numpy.ndarray.resize() function - Python 1 min read Flatten a Matrix in Python using NumPy 1 min read numpy.moveaxis() function | Python 2 min read numpy.swapaxes() function - Python 2 min read Python | Numpy matrix.swapaxes() 1 min read numpy.vsplit() function | Python 2 min read numpy.hsplit() function | Python 2 min read Numpy MaskedArray.reshape() function | Python 3 min read Python | Numpy matrix.squeeze() 1 min read Indexing NumPy ArrayBasic Slicing and Advanced Indexing in NumPy 5 min read numpy.compress() in Python 2 min read Accessing Data Along Multiple Dimensions Arrays in Python Numpy 3 min read How to access different rows of a multidimensional NumPy array? 3 min read numpy.tril_indices() function | Python 1 min read Arithmetic operations on NumPyArrayNumPy Array Broadcasting 6 min read Estimation of Variable | set 1 3 min read Python: Operations on Numpy Arrays 3 min read How to use the NumPy sum function? 4 min read numpy.divide() in Python 3 min read numpy.inner() in python 1 min read Absolute Deviation and Absolute Mean Deviation using NumPy | Python 3 min read Calculate standard deviation of a Matrix in Python 2 min read numpy.gcd() in Python 2 min read Linear Algebra in NumPy ArrayNumpy | Linear Algebra 6 min read Get the QR factorization of a given NumPy array 2 min read How to get the magnitude of a vector in NumPy? 3 min read How to compute the eigenvalues and right eigenvectors of a given square array using NumPY? 2 min read Like