The char.encode()
function in R is simply used to call the str.decode
element-wise.
char.encode(a, encoding=None, errors=None)
The char.encode()
function takes the following parameter values:
a
: This represents the array of strings or Unicode object.encoding
: This represents the name of the encoding. Some encodings include: utf-8
, UTF-16
, UTF-32
, ascii
, cp037
, etc.errors
: This specifies how errors should be handled. This is optional.The char.encode()
function returns an array object.
Note: It is worth noting that the type of output will depend on the value of the
encoding
specified.
import numpy as np# creating an arraymyarray = np.array(["Theo", "How", "Are", "You"])# to eccode the array using ascii encodingTo_encode = np.char.encode(myarray, encoding='cp037')print(To_encode)
numpy
module.myarray
using the array()
function.ascii
encoding using the char.encode()
function. The result is assigned to a variable To_encode
.To_encode
.