NumPy: ljust() function
numpy.core.defchararray.ljust()function
The numpy.core.defchararray.ljust() function returns an array with the elements of a left-justified in a string of length width.
Version: 1.15.0
Syntax:
numpy.core.defchararray.ljust(a, width, fillchar=' ')
Parameter:
Name | Description | Required / Optional |
---|---|---|
a: array_like of str or unicode | Required | |
width: int | The length of the resulting strings | Required |
fillchar: str or unicode | The character to use for padding | 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: numpy.ljust() function
>>> import numpy as np
>>> x = np.char.ljust('w3resource', 30, fillchar = '#')
>>> x
array('w3resource####################', dtype='<U30')
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