Erzeugen Sie einen one-hot-Vektor aus einem aus vier Label bestehenden Label-Vektor, d.h. 0, 1, 2, 3:
>>> num_labels = 4
>>> labels = np.random.randint(4, size=6)[:,None]
>>>
>>> labels
array([[2],
[0],
[3],
[1],
[0],
[1]])
>>>
>>> labels_one_hot = (np.arange(num_labels) == labels).astype(np.float64)
>>> labels_one_hot
array([[ 0., 0., 1., 0.],
[ 1., 0., 0., 0.],
[ 0., 0., 0., 1.],
[ 0., 1., 0., 0.],
[ 1., 0., 0., 0.],
[ 0., 1., 0., 0.]])