多分类标签(one-hot向量)

参考:https://blog.csdn.net/huangbo1221/article/details/79671797

最近学习TensorFlow,例子里面全是mnist这种,鬼知道你里面数据格式是个什么鬼?想用自己的数据训练,于是,第一步先开始制作数据集,开始用one-hot向量打标签;

import numpy as np

label = np.array(np.arange(20))##标签数据,标签从0开始
classes = max(label) + 1 ##类别数为最大数加1
one_hot_label = np.zeros(shape=(label.shape[0],classes))##生成全0矩阵
one_hot_label[np.arange(0,label.shape[0]),label] = 1##相应标签位置置1
print (one_hot_label)

这里面的数字可以是0-n,只要正整数就行,他会生成n个n维的向量;like this。。。。。

猜你喜欢

转载自blog.csdn.net/weixin_41765699/article/details/82796940