numpy.strings.rjust#

strings.rjust(a,width,fillchar='')[source]#

Return an array with the elements ofa right-justified in astring of lengthwidth.

Parameters:
aarray-like, withStringDType,bytes_, orstr_ dtype
widtharray_like, with any integer dtype

The length of the resulting strings, unlesswidth<str_len(a).

fillchararray-like, withStringDType,bytes_, orstr_ dtype

Optional padding character to use (default is space).

Returns:
outndarray

Output array ofStringDType,bytes_ orstr_ dtype,depending on input types

See also

str.rjust

Notes

While it is possible fora andfillchar to have different dtypes,passing a non-ASCII character infillchar whena is of dtype “S”is not allowed, and aValueError is raised.

Examples

>>>importnumpyasnp>>>a=np.array(['aAaAaA','  aA  ','abBABba'])>>>np.strings.rjust(a,width=3)array(['aAaAaA', '  aA  ', 'abBABba'], dtype='<U7')>>>np.strings.rjust(a,width=9)array(['   aAaAaA', '     aA  ', '  abBABba'], dtype='<U9')
On this page