from keras.utils import to_categorical或
from tensorflow.python.keras.utils import to_categorical
比如ascll=[1 2 3 4 5]
one_hot_labels = to_categorical(ascll, num_classes=20)
num_class:one-hot的长度,比如num_class=20,得到的结果就是:
[[0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0]]