[ Web Proxy ]
URL:
Viewing: https://numpy.org/doc/stable/reference/generated/../c-api/../generated/numpy.strings.ljust.html [Back]  [Original]

numpy.strings.ljust — NumPy v2.5 Manual
Back to top
Search the docs ...:

numpy.strings.ljust#

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

Return an array with the elements of a left-justified in a string of length width.

Parameters:
aarray-like, with StringDType, bytes_, or str_ dtype
widtharray_like, with any integer dtype

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

fillchararray-like, with StringDType, bytes_, or str_ dtype

Optional character to use for padding (default is space).

Returns:
outndarray

Output array of StringDType, bytes_ or str_ dtype, depending on input types

See also

str.ljust

Notes

While it is possible for a and fillchar to have different dtypes, passing a non-ASCII character in fillchar when a is of dtype S is not allowed, and a ValueError is raised.

Examples

Try it in your browser!
>>> import numpy as np
>>> c = np.array(['aAaAaA', '  aA  ', 'abBABba'])
>>> np.strings.ljust(c, width=3)
array(['aAaAaA', '  aA  ', 'abBABba'], dtype='<U7')
>>> np.strings.ljust(c, width=9)
array(['aAaAaA   ', '  aA     ', 'abBABba  '], dtype='<U9')

Web Proxy Viewer  |  New URL  |  Original Page