keras np_utils()函数

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Arctic_Beacon/article/details/85292994
from keras.utils import np_utils
N_CLASSES = 3
label = [0,0,0,1,1,1,2,2,2]
train_label = np_utils.to_categorical(label, N_CLASSES)

train_label
Out[21]:
array([[1., 0., 0.],
       [1., 0., 0.],
       [1., 0., 0.],
       [0., 1., 0.],
       [0., 1., 0.],
       [0., 1., 0.],
       [0., 0., 1.],
       [0., 0., 1.],
       [0., 0., 1.]], dtype=float32)

类似于tf.one_hot()

猜你喜欢

转载自blog.csdn.net/Arctic_Beacon/article/details/85292994
今日推荐