numpy之one-hot
来源:互联网 发布:iphone连mac充电好吗 编辑:程序博客网 时间:2024/06/05 03:27
a = np.array([1, 0, 3])#数据列,one-hot编码之后非零的列n_class = a.max() + 1n_sample = a.shape[0]b = np.zeros((n_sample, n_class))#3个样本,4个类别b[:, a] = 1#非零列赋值为1barray([[ 0., 1., 0., 0.], [ 1., 0., 0., 0.], [ 0., 0., 0., 1.]])>>>
使用np.eye生成M*N矩阵,后面跟的数组说明1偏移的位置
values = np.array([1, 0, 3])n_values = np.max(values) + 1np.eye(n_values)[values]array([[ 0., 1., 0., 0.], [ 1., 0., 0., 0.], [ 0., 0., 0., 1.]])
例如
np.eye(4,3)[np.array([1, 1, 1, 1])]array([[ 0., 1., 0.], [ 0., 1., 0.], [ 0., 1., 0.], [ 0., 1., 0.]])
values = np.array([1, 0, 3,1,2,1,2])n_values = np.max(values) + 1np.eye(n_values)[values]array([[ 0., 1., 0., 0.], [ 1., 0., 0., 0.], [ 0., 0., 0., 1.], [ 0., 1., 0., 0.], [ 0., 0., 1., 0.], [ 0., 1., 0., 0.], [ 0., 0., 1., 0.]])
阅读全文
0 0
- numpy之one-hot
- 数据处理之one-hot
- 数据预处理之独热编码(One-Hot Encoding)
- 数据预处理之独热编码(One-Hot Encoding)
- 独热码one-hot code
- One Hot Code---独热码
- one-hot编码
- One hot encoding
- One-Hot Encoding
- one hot coding
- one-hot编码
- One-Hot Encoding
- one-hot编码
- One-Hot Encoding
- 关于One-hot编码
- 独热码one-hot code
- One-hot encoding 数据处理
- One-Hot Encoding
- ART深入浅出(7)
- VSTO Office二次开发键盘鼠标钩子使用整理
- java使用FileUpload实现文件的上传和下载
- java注解入门
- JAVA 21个技术点
- numpy之one-hot
- bzoj 1005: [HNOI2008]明明的烦恼
- 10.9离线赛
- Django HTTP请求的处理流程
- Android 颜色透明度换算
- web--前端之js代码8
- LeetCode 290. Word Pattern
- 关于视频播放VideoView的一些总结
- Material Design UI控件