1note:text contains your string or already read textfile
2
3import numpy as np
4text = 'hello'
5vocab=sorted(set(text))
6char_to_ind = {char:ind for ind,char in enumerate(vocab)}
7encoded_text = np.array([char_to_ind[c]for c in text])
8
9your string has been encoded