Thursday, January 22, 2026
HomeLanguagesnumpy.defchararray.decode() in Python

numpy.defchararray.decode() in Python

numpy.core.defchararray.decode(arr, encoding): This numpy function decode the string(object) based on the specified codec.

Parameters:
arr : array-like or string.
encoding : [str] Name of codec being followed.
error : Specifying how to handle error.

Returns : Decoded string

Code:




# Python Program illustrating 
# numpy.char.decode() method 
import numpy as np 
  
arr1 = ['eAAAa', 'ttttds', 'AAtAAt']
arr2 = ['11sf', 'sdsf2', '1111f2']
  
print ("\narr1 : ", arr1)
print ("\narr2 : ", arr2)
  
# Using np.char.encode()
encode_arr1 = np.char.encode(arr1, encoding ='cp037')
print ("\nEncoded arr1 : \n", encode_arr1)
  
encode_arr2 = np.char.encode(arr2, encoding ='utf8')
print ("\nEncoded arr2 : \n", encode_arr2)
  
# Using np.char.decode()
decode_arr1 = np.char.decode(encode_arr1, encoding ='cp037')
print ("\nDecoded arr1 : \n", decode_arr1)
  
decode_arr2 = np.char.decode(encode_arr2, encoding ='cp037')
print ("\nDecoded arr1 : \n", decode_arr2)
  
decode_arr2 = np.char.decode(encode_arr2, encoding ='utf8')
print ("\nDecoded arr1 : \n", decode_arr2)


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']

Decoded arr1 : 
 ['eAAAa' 'ttttds' 'AAtAAt']

Decoded arr2 : 
 ['\x91\x91ËÃ' 'ËÀËÃ\x16' '\x91\x91\x91\x91Ã\x16']

Decoded arr2 : 
 ['11sf' 'sdsf2' '1111f2']
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32475 POSTS0 COMMENTS
Milvus
119 POSTS0 COMMENTS
Nango Kala
6847 POSTS0 COMMENTS
Nicole Veronica
11977 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12064 POSTS0 COMMENTS
Shaida Kate Naidoo
6986 POSTS0 COMMENTS
Ted Musemwa
7220 POSTS0 COMMENTS
Thapelo Manthata
6933 POSTS0 COMMENTS
Umr Jansen
6912 POSTS0 COMMENTS