numpy.defchararray.decode() in Python Last Updated : 28 Nov, 2018 Comments Improve Suggest changes Like Article Like Report 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: Python3 1== # 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'] Comment More infoAdvertise with us Next Article numpy.defchararray.decode() in Python mohit gupta_omg :) Follow Improve Article Tags : Python Python-numpy Python numpy-String Operation Practice Tags : python Similar Reads numpy.defchararray.add() in Python numpy.core.defchararray.add(arr1, arr2): Concatenates two strings element-wise. Parameters: arr1 : array-like or string. arr2 : array-like or string. Returns : Concatenates String. Code #1: Python3 1== # Python Program illustrating # numpy.char.add() method import numpy as np arr1 = ['vdteteAAAa', ' 1 min read 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 of resulting string. fillchar : Padding character. Default is space.Returns : Copy of array with centered string. Code #1:  Python3 # Python 1 min read numpy.defchararray.capitalize() in Python numpy.core.defchararray.multiply(arr, n): Capitalizes the first letter of string element-wise. Parameters: arr : array-like or string. Returns : Capitalized first letter of the string. Code #1: Python3 1== # Python Program illustrating # numpy.char.capitalize() method import numpy as np arr1 = ['eAA 1 min read numpy.defchararray.encode() in Python numpy.core.defchararray.encode(arr, encoding): This numpy 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: Python3 # Pyth 1 min read numpy.defchararray.multiply() in Python numpy.core.defchararray.multiply(arr, n): Concatenates strings 'n' times element-wise. Parameters: arr : array-like or string. n : [array-like] no. of times we want to concatenate. Returns : Concatenated String 'n' times element-wise. Code #1: Python3 1== # Python Program illustrating # numpy.char.m 1 min read numpy.asarray() in Python numpy.asarray()function is used when we want to convert input to an array. Input can be lists, lists of tuples, tuples, tuples of tuples, tuples of lists and arrays. Syntax : numpy.asarray(arr, dtype=None, order=None) Parameters : arr : [array_like] Input data, in any form that can be converted to a 2 min read numpy.array_repr() in Python numpy.array_repr()function is used to convert an array to a string. Syntax : numpy.array_repr(arr, max_line_width=None, precision=None, suppress_small=None) Parameters : arr : [array_like] Input array. max_line_width : [int, optional] The maximum number of columns the string should span. Newline cha 2 min read How to JSON decode in Python? When working with JSON data in Python, we often need to convert it into native Python objects. This process is known as decoding or deserializing. The json module in Python provides several functions to work with JSON data, and one of the essential tools is the json.JSONDecoder() method. This method 5 min read codecs.decode() in Python With the help of codecs.decode() method, we can decode the binary string into normal form by using codecs.decode() method. Syntax : codecs.decode(b_string) Return : Return the decoded string. Example #1 : In this example we can see that by using codecs.decode() method, we are able to get the decoded 1 min read numpy.fromiter() function â Python NumPy's fromiter() function is a handy tool for creating a NumPy array from an iterable object. This iterable can be any Python object that provides elements one at a time. The function is especially useful when you need to convert data from a custom data source, like a file or generator, into a Num 2 min read Like