numpy.defchararray.encode() in Python
numpy.core.defchararray.encode(arr, encoding): This nuympy function encodes the string(object) based on the specified codec.
Parameters:
arr : array-like or string.
encoding : [str] Name of encoding being followed.
error : Specifying how to handle error.Returns : Encoded string
Code:
# Python Program illustrating # numpy.char.encode() method import numpy as np arr1 = ['eAAAa', 'ttttds', 'AAtAAt'] arr2 = ['11sf', 'sdsf2', '1111f2'] # Printing the array print ("\narr1 : ", arr1) print ("\narr2 : ", arr2) print ("\nEncoded arr1 : \n", np.char.encode(arr1, encoding ='cp037')) print ("\nEncoded arr2 : \n", np.char.encode(arr2, encoding ='utf8')) print ("\nEncoded arr2 : \n", np.char.encode(arr2, encoding ='utf8', errors = 'strict')) |
chevron_right
filter_none
Output:
arr1 : ['eAAAa', 'ttttds', 'AAtAAt'] arr2 : ['11sf', 'sdsf2', '1111f2'] Encoded arr1 : [b'\x85\xc1\xc1\xc1\x81' b'\xa3\xa3\xa3\xa3\x84\xa2' b'\xc1\xc1\xa3\xc1\xc1\xa3'] Encoded arr2 : [b'11sf' b'sdsf2' b'1111f2'] Encoded arr2 : [b'11sf' b'sdsf2' b'1111f2']
Recommended Posts:
- Python | Index of Non-Zero elements in Python list
- Reading Python File-Like Objects from C | Python
- Python | Convert list to Python array
- Python | Merge Python key values to list
- Important differences between Python 2.x and Python 3.x with examples
- Python | Sort Python Dictionaries by Key or Value
- Python | Add Logging to Python Libraries
- Python | Add Logging to a Python Script
- Python | Set 4 (Dictionary, Keywords in Python)
- Python | Visualizing O(n) using Python
- JavaScript vs Python : Can Python Overtop JavaScript by 2020?
- Any & All in Python
- SHA in Python
- abs() in Python
- pow() in Python
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.



