Skip to content

Commit

Permalink
Merge pull request numpy#21904 from ZicsX/doc-string-for-np-char-center
Browse files Browse the repository at this point in the history
DOC: Add usage example to np.char.center docstring
  • Loading branch information
melissawm authored Jul 2, 2022
2 parents eea02b0 + 60f1d14 commit 549fe95
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions numpy/core/defchararray.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,22 @@ def center(a, width, fillchar=' '):
See Also
--------
str.center
Notes
-----
This function is intended to work with arrays of strings. The
fill character is not applied to numeric types.
Examples
--------
>>> c = np.array(['a1b2','1b2a','b2a1','2a1b']); c
array(['a1b2', '1b2a', 'b2a1', '2a1b'], dtype='<U4')
>>> np.char.center(c, width=9)
array([' a1b2 ', ' 1b2a ', ' b2a1 ', ' 2a1b '], dtype='<U9')
>>> np.char.center(c, width=9, fillchar='*')
array(['***a1b2**', '***1b2a**', '***b2a1**', '***2a1b**'], dtype='<U9')
>>> np.char.center(c, width=1)
array(['a', '1', 'b', '2'], dtype='<U1')
"""
a_arr = numpy.asarray(a)
Expand Down

0 comments on commit 549fe95

Please sign in to comment.