![]() |
VOOZH | about |
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 Content
In this article, we’ll explore the various string functions provided by NumPy along with their examples.
['geeks' 'for'] geeks
['geeks', 'for', 'geeks'] ['geeks', ' for', ' geeks']
g-e-e-k-s ['g-e-e-k-s' 'f:o:r']
| FUNCTION | DESCRIPTION |
|---|---|
| numpy.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 form |
| numpy.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.rpartition | Partition (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. |
[1 0 1] [0 1 0]
[ 0 -1 0] [-1 0 -1]
False False
| FUNCTION | DESCRIPTION |
|---|---|
| numpy.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 string |
| numpy.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. |
False
True
numpy.greater(): This function checks whether string1 is greater than string2 or not.
True
| FUNCTION | DESCRIPTION |
|---|---|
| numpy.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. |
array: Creates a new NumPy array from a list or similar data structure.
chararray: Creates a NumPy array specialized for handling string operations.
asarray: Converts input data into a NumPy array, avoiding unnecessary copying if already an array.
FUNCTIONS | DESCRIPTION |
|---|---|
chararray | NumPy array for string operations, providing vectorized string processing capabilities. |
array | Creates a NumPy array from input data |
Converts input data into a NumPy array without copying |