numpy one hot 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.]])
Example 3: numpy one hot
one_hot_encode=pandas.get_dummies(array)