MCPcopy Create free account
hub / github.com/numpy/numpy / ljust

Function ljust

numpy/core/defchararray.py:1068–1100  ·  view source on GitHub ↗

Return an array with the elements of `a` left-justified in a string of length `width`. Calls `str.ljust` element-wise. Parameters ---------- a : array_like of str or unicode width : int The length of the resulting strings fillchar : str or unicode, optiona

(a, width, fillchar=' ')

Source from the content-addressed store, hash-verified

1066
1067@array_function_dispatch(_just_dispatcher)
1068def ljust(a, width, fillchar=' '):
1069 """
1070 Return an array with the elements of `a` left-justified in a
1071 string of length `width`.
1072
1073 Calls `str.ljust` element-wise.
1074
1075 Parameters
1076 ----------
1077 a : array_like of str or unicode
1078
1079 width : int
1080 The length of the resulting strings
1081 fillchar : str or unicode, optional
1082 The character to use for padding
1083
1084 Returns
1085 -------
1086 out : ndarray
1087 Output array of str or unicode, depending on input type
1088
1089 See Also
1090 --------
1091 str.ljust
1092
1093 """
1094 a_arr = numpy.asarray(a)
1095 width_arr = numpy.asarray(width)
1096 size = int(numpy.max(width_arr.flat))
1097 if numpy.issubdtype(a_arr.dtype, numpy.bytes_):
1098 fillchar = asbytes(fillchar)
1099 return _vec_string(
1100 a_arr, type(a_arr.dtype)(size), 'ljust', (width_arr, fillchar))
1101
1102
1103@array_function_dispatch(_unary_op_dispatcher)

Callers 1

ljustMethod · 0.85

Calls 3

asbytesFunction · 0.90
_vec_stringFunction · 0.90
maxMethod · 0.45

Tested by

no test coverage detected