numpy.strings.center#
- strings.center(a, width, fillchar=' ')[source]#
- Return a copy of a with its elements centered in a string of length width. - Parameters:
- aarray-like, with StringDType,bytes_, orstr_dtype
- widtharray_like, with any integer dtype
- The length of the resulting strings, unless - width < str_len(a).
- fillchararray-like, with StringDType,bytes_, orstr_dtype
- Optional padding character to use (default is space). 
 
- aarray-like, with 
- Returns:
- outndarray
- Output array of - StringDType,- bytes_or- str_dtype, depending on input types
 
 - See also - Notes - While it is possible for - aand- fillcharto have different dtypes, passing a non-ASCII character in- fillcharwhen- ais of dtype “S” is not allowed, and a- ValueErroris raised.- Examples - >>> import numpy as np >>> c = np.array(['a1b2','1b2a','b2a1','2a1b']); c array(['a1b2', '1b2a', 'b2a1', '2a1b'], dtype='<U4') >>> np.strings.center(c, width=9) array([' a1b2 ', ' 1b2a ', ' b2a1 ', ' 2a1b '], dtype='<U9') >>> np.strings.center(c, width=9, fillchar='*') array(['***a1b2**', '***1b2a**', '***b2a1**', '***2a1b**'], dtype='<U9') >>> np.strings.center(c, width=1) array(['a1b2', '1b2a', 'b2a1', '2a1b'], dtype='<U4')