Pengkodean int ke chr dalam python dan sebaliknya
# encode the text and map each character to an integer and vice versa
# we create two dictionaries:
# 1. int2char, which maps integers to characters
# 2. char2int, which maps characters to unique integers
chars = tuple(set(text))
int2char = {ind:char for ind,char in enumerate(chars)}
char2int = {char:ind for ind,char in enumerate(chars)}
# encode the text
encoded = np.array([char2int[ch] for ch in text])
Nasty Newt