Created
October 23, 2018 12:04
-
-
Save takotab/eb32d2819e53deedd3b52c557d34a458 to your computer and use it in GitHub Desktop.
one hot vector python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
def to_one_hot(target_vector, n_labels = None): | |
if n_labels is None: | |
n_labels = len(set(target_vector)) | |
return np.eye(n_labels)[target_vector] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment