numpy.defchararray.center() in Python
numpy.core.defchararray.center(arr, width, fillchar): Centers the element of the string element-wise.
Parameters:
arr : array-like or string.
width : Length og resulting string.
fillchar : Padding character. Default is space.Returns : Copy of array with centerd string.
Code #1:
# Python Program illustrating # numpy.char.center() method import numpy as np arr1 = ['eAAAa', 'ttttds', 'AAtAAt'] print ("arr1 : ", arr1) print ("\narr1 : ", np.char.center(arr1, 7, fillchar ='z')) print ("\narr1 : ", np.char.center(arr1, [9, 9, 11], fillchar =['z', '1', '3'])) print ("\narr1 : ", np.char.center(arr1, 11, fillchar ='z')) |
chevron_right
filter_none
Output:
arr1 : ['eAAAa', 'ttttds', 'AAtAAt'] centered arr1 : ['zeAAAaz' 'zttttds' 'zAAtAAt'] centered arr1 : ['zzeAAAazz' '11ttttds1' '333AAtAAt33'] centered arr1 : ['zzzeAAAazzz' 'zzzttttdszz' 'zzzAAtAAtzz']
Code #2:
# Python Program illustrating # numpy.char.center() method import numpy as np arr2 = ['11sf', 'sdsf2', '1111f2'] print ("arr2 : ", arr2) # Will throw Error print ("\narr2 : ", np.char.center(arr2)) |
chevron_right
filter_none
Output:
arr2 : ['11sf', 'sdsf2', '1111f2'] TypeError: center() missing 1 required positional argument: 'width'
Recommended Posts:
- Python | Merge Python key values to list
- Reading Python File-Like Objects from C | Python
- Important differences between Python 2.x and Python 3.x with examples
- Python | Convert list to Python array
- Python | Index of Non-Zero elements in Python list
- Python | Sort Python Dictionaries by Key or Value
- Python | Add Logging to a Python Script
- Python | Add Logging to Python Libraries
- Python | Set 4 (Dictionary, Keywords in Python)
- Python | Visualizing O(n) using Python
- JavaScript vs Python : Can Python Overtop JavaScript by 2020?
- zip() in Python
- Any & All in Python
- bin() in Python
- Python vs PHP
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



