numpy one hot encoding 2d code example Example: one hot encoding numpy labels = (np.arange(num_labels) == labels[:,None]).astype(np.float32)