NumPy: rstrip() function
numpy.core.defchararray.rstrip() function
For each element in a given array numpy.core.defchararray.rstrip() function returns a copy with the trailing characters removed.
Calls str.rstrip element-wise.
Version: 1.15.0
Syntax:
numpy.core.defchararray.rstrip(a, chars=None)
Parameter:
Name | Description | Required / Optional |
---|---|---|
a: array-like of str or unicode | Required | |
chars: str or unicode | The chars argument is a string specifying the set of characters to be removed. If omitted or None, the chars argument defaults to removing whitespace. The chars argument is not a suffix; rather, all combinations of its values are stripped. | Optional |
Return value:
out : ndarray - 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.rstrip() function
import numpy as np
str1 = 'Python NumPy '
print("Original string: ",str1)
print("After trailing whitepsace are removed:")
print(np.char.rstrip(str1))
Output:
Original string: Python NumPy After trailing whitepsace are removed: Python NumPy
Pictorial Presentation:
Python - NumPy Code Editor:
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework