122
NumPy String Functions
NumPy contains the following functions for the operations on the arrays of dtype string.
SN | Function | Description |
---|---|---|
1 | add() | It is used to concatenate the corresponding array elements (strings). |
2 | multiply() | It returns the multiple copies of the specified string, i.e., if a string ‘hello’ is multiplied by 3 then, a string ‘hello hello’ is returned. |
3 | center() | It returns the copy of the string where the original string is centered with the left and right padding filled with the specified number of fill characters. |
4 | capitalize() | It returns a copy of the original string in which the first letter of the original string is converted to the Upper Case. |
5 | title() | It returns the title cased version of the string, i.e., the first letter of each word of the string is converted into the upper case. |
6 | lower() | It returns a copy of the string in which all the letters are converted into the lower case. |
7 | upper() | It returns a copy of the string in which all the letters are converted into the upper case. |
9 | split() | It returns a list of words in the string. |
9 | splitlines() | It returns the list of lines in the string, breaking at line boundaries. |
10 | strip() | Returns a copy of the string with the leading and trailing white spaces removed. |
11 | join() | It returns a string which is the concatenation of all the strings specified in the given sequence. |
12 | replace() | It returns a copy of the string by replacing all occurrences of a particular substring with the specified one. |
13 | decode() | It is used to decode the specified string element-wise using the specified codec. |
14 | encode() | It is used to encode the decoded string element-wise. |
numpy.char.add() method example
Output:
Concatenating two string arrays: ['Welcome to Tutor Aspire' 'Hi read python']
numpy.char.multiply() method example
Output:
Printing a string multiple times: hello hello hello
numpy.char.center() method example
Output:
Padding the string through left and right with the fill char * *****tutoraspire*****
numpy.char.capitalize() method example
Output:
Capitalizing the string using capitalize()... Welcome to Tutor Aspire
numpy.char.title() method example
Output:
Converting string into title cased version... Welcome to Tutor Aspire
numpy.char.lower() method example
Output:
Converting all the characters of the string into lowercase... Welcome to Tutor Aspire
numpy.char.upper() method example
Output:
Converting all the characters of the string into uppercase... Welcome to Tutor Aspire
numpy.char.split() method example
Output:
Splitting the String word by word.. ['Welcome', 'To', 'tutoraspire']
numpy.char.splitlines() method example
Output:
Splitting the String line by line.. ['Welcome', 'To', 'tutoraspire']
numpy.char.strip() method example
Output:
Original String: Welcome to Tutor Aspire Removing the leading and trailing whitespaces from the string Welcome to Tutor Aspire
numpy.char.join() method example
Output:
H:M
numpy.char.replace() method example
Output:
Original String: Welcome to Tutor Aspire Modified String: www. tutoraspire
numpy.char.encode() and decode() method example
Output:
b'xa6x85x93x83x96x94[email protected]xa3[email protected]x91x81xa5x81xa3x97x96x89x95xa3' Welcome to Tutor Aspire
Next TopicNumPy Mathematical Functions