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 arraymyarray = 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
numpymodule. - Line 4: We use the
array()function to create an array calledmyarray. - Line 7: We remove the leading set of characters,
"Th", from each of the elements of the array to implement thechar.strip()function on themyarray. Next, we print the result to the console.