What is the numpy.char.capitalize() function in Python?
Overview
The char.capitalize() function in Python is used to convert only the first character of each element of an input array of string to uppercase.
Syntax
char.capitalize(a)
Parameter value
The char.capitalize() function takes a single and mandatory parameter value a, which represents the input array of strings that need to be capitalized.
Return value
The char.capitalize() function returns an array of strings or Unicode, depending on the input types.
Code example
import numpy as np# creating an arraymyarray = np.array(["hello", "theophilus ,", 'HOW', "are", "you today?"])# implementing the char.capitalize() functionprint(np.char.capitalize(myarray))
Code explanation
- Line 1: We import the
numpymodule. - Line 4: We create an array
myarray, using thearray()function. - Line 7: We implement the
char.capitalize()function on the arraymyarrayand print the result to the console.