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

Overview

In Python, the char.strip() function returns an array where the input array’s leading character(s) is removed.

Syntax

char.split(a, char)

Parameter value

This function takes the following parameter values:

  • a: This is the input array of strings or Unicode.
  • char: This is the character(s) to be removed.

Return value

This function returns an output array of strings or Unicode, depending on the input type passed to the function.

Example

import numpy as np
# creating an array
myarray = np.array(["That", "There", "These", "They"])
# implementing the char.strip() function to remove `Th`
print(np.char.strip(myarray, "Th"))

Explanation

  • Line 1: We import the numpy module.
  • Line 4: We use the array() function to create an array called myarray.
  • Line 7: We remove the leading set of characters, "Th", from each of the elements of the array to implement the char.strip() function on the myarray. Next, we print the result 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