numpy.char.rjust#
- char.rjust(a, width, fillchar=' ')[source]#
返回一个数组,其中 a 的元素在长度为 width 的字符串中右对齐。
- 参数:
- a类数组,具有
StringDType
、bytes_
或str_
dtype - width类数组,具有任何整数 dtype
结果字符串的长度,除非
width < str_len(a)
。- fillchar类数组,具有
StringDType
、bytes_
或str_
dtype 可选的填充字符(默认为空格)。
- a类数组,具有
- 返回:
- outndarray
输出数组为
StringDType
、bytes_
或str_
dtype,具体取决于输入类型
另请参阅
备注
虽然
a
和fillchar
可以具有不同的 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')