Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

NumPy: lstrip() function

numpy.core.defchararray.lstrip() function

For each element in a given array numpy.core.defchararray.lstrip() function returns a copy with the leading characters removed.

Version: 1.15.0

Syntax:

numpy.core.defchararray.lstrip(a, chars=None)

Parameter:

Name Description Required /
Optional
a: array_like, {str, unicode} Input array. Required
chars: {str, unicode} Separator to split each string element in a. Optional

Return value:

out : ndarray, {str, unicode} - Output array of str or unicode, depending on input type.

Note:

The 'chararray' class exists for backwards compatibility with Numarray, it is not recommended for new development. Starting from numpy 1.4, if one needs arrays of strings, it is recommended to use arrays of 'dtype' 'object_', 'string_' or 'unicode_', and use the free functions in the 'numpy.char' module for fast vectorized string operations.

Some methods will only be available if the corresponding string method is available in your version of Python.

The preferred alias for 'defchararray' is 'numpy.char'.

Example-1: numpy.lstrip() function

import numpy as np 
str1 = '   Python NumPy'
print("Original string: ",str1)
print("After leading whitepsace are removed:")
print(np.char.lstrip(str1))

Output:

Original string:     Python NumPy
After leading whitepsace are removed:
Python NumPy

Pictorial Presentation:

NumPy String operation: lstrip() function

Python - NumPy Code Editor:

Previous: lower()
Next: partition()