Keras中to_categorical用法

to_categorical使用

from keras.utils.np_utils import to_categorical

int_labels = [1,2,9,4]
labels = ["1","8"]
categorical_labels_1 = to_categorical(int_labels)
categorical_labels_2 = to_categorical(labels)

print(categorical_labels_1)
print(categorical_labels_2)

运行结果如下:

[[0. 1. 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. 1.]
 [0. 0. 0. 0. 1. 0. 0. 0. 0. 0.]]
[[0. 1. 0. 0. 0. 0. 0. 0. 0.]
 [0. 0. 0. 0. 0. 0. 0. 0. 1.]]

你可能感兴趣的:(Keras中to_categorical用法)