Skip to content

Instantly share code, notes, and snippets.

@takotab
Created October 23, 2018 12:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takotab/eb32d2819e53deedd3b52c557d34a458 to your computer and use it in GitHub Desktop.
Save takotab/eb32d2819e53deedd3b52c557d34a458 to your computer and use it in GitHub Desktop.
one hot vector python
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