What is the numpy.char.title() function from NumPy in Python?

Overview

The char.title(() function in Python is used to return an element-wise titled cased version of an input array of strings or Unicode.

Syntax

char.title(a)

Parameter

The char.title(() function takes a single parameter value, a, which represents the input array of strings or Unicode.

Return value

The char.title(() function returns an array of strings or Unicode, depending on the input type passed to the function.

Example

Let’s look at the code below:

import numpy as np
# creating an array
myarray1 = np.array(["ThIS", "IS", "ThE", "Title", "OF", "this", 'coDE'])
# implementing the char.title() function
print(np.char.title(myarray1))
# creating another array
myarray2 = np.array(["THIS IS the TitlE of this code"])
# implementing the char.title() function
print(np.char.title(myarray2))

Explanation

  • Line 1: We import the NumPy module.
  • Lines 4 and 9: We create a string of arrays mystring1 and mystring2 using the array() function.
  • Lines 6 and 11: We implement the char.title() function on both input arrays, myarray1 and myarray2, and print the results to the console.

New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources