numpy string operations | title() function (original) (raw)
Last Updated : 14 Jan, 2019
numpy.core.defchararray.title(arr)
: function is used to Return element-wise title cased version of string or unicode.Title case words start with uppercase characters, all remaining cased characters are lowercase.
Parameters:
arr : [ array_like ] Input array which may be str or unicode.Returns : [ndarray] Output array of str or unicode, depending on input type.
Code #1:
import
numpy as geek
in_arr
=
geek.array([
'p4q r'
,
'4q rp'
,
'q rp4'
,
'rp4q'
])
print
(
"input array : "
, in_arr)
out_arr
=
geek.char.title(in_arr)
print
(
"output titled array :"
, out_arr)
Output:
input array : ['p4q r' '4q rp' 'q rp4' 'rp4q'] output titled array : ['P4Q R' '4Q Rp' 'Q Rp4' 'Rp4Q']
Code #2:
import
numpy as geek
in_arr
=
geek.array([
'geeks'
,
'for'
,
'geeks'
])
print
(
"input array : "
, in_arr)
out_arr
=
geek.char.title(in_arr)
print
(
"output titled array :"
, out_arr )
Output:
input array : ['geeks' 'for' 'geeks'] output titled array : ['Geeks' 'For' 'Geeks']
Similar Reads
- numpy string operations | strip() function numpy.core.defchararray.strip(arr, chars=None) is another function for doing string operations in numpy. It returns a copy with the leading and trailing characters removed for each element in arr. Parameters: arr : array_like of str or unicode. char : [str or unicode, optional] the set of characters 2 min read
- numpy string operations | zfill() function numpy.core.defchararray.zfill(arr, width) is another function for doing string operations in numpy. For each element in the array it returns the numeric string left-filled with zeros.The number of left filled zeros happen according to the width. Parameters: arr : array_like of str or unicode.Input a 2 min read
- Numpy - String Functions & Operations 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 String OperationsString Information String Comparison In this article, we’ll explore the v 5 min read
- numpy string operations | translate() function numpy.core.defchararray.translate(arr, table, deletechars=None) is another function for doing string operations in numpy. For each element in arr, it returns a copy of the string where all characters occurring in the optional argument deletechars are removed, and the remaining characters have been m 1 min read
- numpy string operations | upper() function numpy.core.defchararray.upper(arr): function is used to return an array with the elements converted to uppercase. Parameters: arr : [ array_like ] Input array which may be str or unicode. Returns : [ndarray] Output uppercased array of str or unicode, depending on input type. Code #1: # Python Progra 1 min read
- numpy string operations | rstrip() function numpy.core.defchararray.rstrip(arr, chars=None) is another function for doing string operations in numpy. It returns a copy with the trailing characters removed for each element in arr. Parameters: arr : array_like of str or unicode. char : [str or unicode, optional] the set of characters to be remo 2 min read
- numpy string operations | split() function numpy.core.defchararray.split(arr, sep=None, maxsplit=None) is another function for doing string operations in numpy.It returns a list of the words in the string, using sep as the delimiter string for each element in arr. Parameters: arr : array_like of str or unicode.Input array. sep : [ str or uni 2 min read
- numpy string operations | lower() function numpy.core.defchararray.lower(arr) function is used to return an array with the elements converted to lowercase. Parameters: arr : [ array_like ] Input array which may be str or unicode. Returns : [ndarray] Output lowercased array of str or unicode, depending on input type. Code #1: # Python Program 1 min read
- Numpy string operations | rindex() function numpy.core.defchararray.rindex() function, raises ValueError when the substring sub is not found. Calls str.rindex element-wise. Syntax : numpy.core.defchararray.rindex(arr, sub, start = 0, end = None) Parameters : arr : [array-like of str or unicode] Array-like of str . sub : [str or unicode] Input 1 min read
- numpy string operations | rsplit() function numpy.core.defchararray.rsplit(arr, sep=None, maxsplit=None) is another function for doing string operations in numpy. It returns a list of the words in the string, using sep as the delimiter string for each element in arr. The rsplit() method splits every string array element into a list, starting 2 min read