如何在 python 中实现一种没有任何 ML 帧的热编码?

How to implement one hot encoding without any ML frames in python?

在没有任何 MLframe 的情况下进行 MNIST 教程,但卡在了一个热编码阶段

y 包含数字图像的标签数据

0、1、2、3、4、5、6、7、8、9

它的大小是 (10000, )

我想将每个类别编号转换为一个热编码数组

0 : 1 0 0 0 0 0 0 0 0 0 0
1 : 0 1 0 0 0 0 0 0 0 0 0
2:0 0 1 0 0 0 0 0 0 0 0 等等

所以我做了一个代码

import numpy as np
y_one=np.zeros(y.size, 10)
y_one[np.arange(y.size), y]=1

它说 'data type not understood'

在这种情况下,如何在没有 sklearn 或 tf 的情况下实现一种热编码?

np.zeros 函数的 shape 参数传递整数元组

y_one = np.zeros((y.size, 10))