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: rjust() function

numpy.core.defchararray.rjust() function

The numpy.core.defchararray.rjust() function returns an array with the elements of a right-justified in a string of length width.
Calls str.rjust element-wise.

Version: 1.15.0

Syntax:

numpy.core.defchararray.rjust(a, width, fillchar=' ')

Parameter:

Name Description Required /
Optional
a: array-like of str or unicode Required
width: int The length of the resulting strings Require
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.rjust() function

>>> import numpy as np
>>> x = np.char.rjust('w3resource', 30, fillchar = '#')
>>> x
array('####################w3resource', dtype='<U30')

Pictorial Presentation:

NumPy String operation: rjust() function

Python - NumPy Code Editor:

Previous: replace()
Next: rpartition()