numpy.strings.rjust#

strings.rjust(a, width, fillchar=' ')[源代码]#

返回一个数组,该数组中的元素在长度为 width 的字符串中右对齐.

参数:
a: 类数组,具有 StringDType , bytes_str_ dtype类数组,具有
width类数组对象,具有任何整数dtype

结果字符串的长度,除非 width < str_len(a) .

fillchar : 类数组对象,具有 StringDType , bytes_str_ dtype类数组,具有

要使用的可选填充字符(默认为空格).

返回:
outndarray

StringDType , bytes_str_ dtype 的输出数组,具体取决于输入类型

参见

str.rjust

注释

虽然 afillchar 可能具有不同的dtype,但不允许在 a 的dtype为"S"时在 fillchar 中传递非ASCII字符,并且会引发 ValueError .

示例

>>> import numpy as np
>>> 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')