I have a list of strings that I want to convert to a simple integer array.
Example:
my_list = ['This is a string', 'This is a string', 'Hi! I am a string', 'I dislike strings', 'This is a string', 'Not a number']
Converted to:
[0, 0, 1, 2, 0, 3]
Elements in my_list
that have the same value will all end up with the same integer in the converted array.
The idea behind this is that I want to utilize the following syntax (from matplotlib) to make a scatter chart, and it doesn't seem to like it when y_train
or i
is a string:
X_train_small_pca[y_train == i, 0]
How can I convert my list into integers, as above?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…