Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

encoding character or string to integer in python

note:text contains your string or already read textfile 

import numpy as np
text = 'hello'
vocab=sorted(set(text))
char_to_ind = {char:ind for ind,char in enumerate(vocab)}
encoded_text = np.array([char_to_ind[c]for c in text])

your string has been encoded
Comment

PREVIOUS NEXT
Code Example
Python :: how to check if some file exists in python 
Python :: python sort list by rule 
Python :: pandas data frame from part of excel 
Python :: How to change application icon of pygame 
Python :: importing a python file from another folder 
Python :: array slicing python 
Python :: how to loop through lines python 
Python :: pipeline model coefficients 
Python :: convert string ranges list python 
Python :: django admin text box 
Python :: python - subtracting dictionary values 
Python :: Python NumPy transpose Function Syntax 
Python :: get all subarrays of an array python 
Python :: beautifulsoup remove tag with class 
Python :: ski learn decision tree 
Python :: python string to lowercase 
Python :: aiohttp specify app IP 
Python :: update dataframe based on value from another dataframe 
Python :: python indent print 
Python :: ensemble model using voting classifier 
Python :: panda loc conditional 
Python :: python download images from unsplash 
Python :: rolling std dev of a pandas series 
Python :: histogram python 
Python :: logging python 
Python :: flask arguments in url 
Python :: add element to array list python 
Python :: migrations.RunPython 
Python :: concatenate strings of numpy array python 
Python :: como poner estado a un bot en discord 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =