Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

function
python
numpy
communitycreator

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

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

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"))
Implementing the char.strip() function

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.

RELATED TAGS

function
python
numpy
communitycreator

CONTRIBUTOR

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring