how to one hot encode numpy array code example
Example 1: one hot encoding numpy
labels = (np.arange(num_labels) == labels[:,None]).astype(np.float32)
Example 2: np one hot encoding
>>> a = np.array([1, 0, 3])
>>> b = np.zeros((a.size, a.max()+1))
>>> b[np.arange(a.size),a] = 1
>>> b
array([[ 0., 1., 0., 0.],
[ 1., 0., 0., 0.],
[ 0., 0., 0., 1.]])