Skip to content

Instantly share code, notes, and snippets.

@yuki-inaho
Last active June 8, 2021 07:19
Show Gist options
  • Select an option

  • Save yuki-inaho/5be2ac911847ad253bdf1bf5af165369 to your computer and use it in GitHub Desktop.

Select an option

Save yuki-inaho/5be2ac911847ad253bdf1bf5af165369 to your computer and use it in GitHub Desktop.
categorical-labelled mask -> one-hot type expression
import numpy as np
def np_class2one_hot(category_array: np.ndarray, n_classes: int) -> np.ndarray:
res = np.eye(n_classes)[np.array(category_array).reshape(-1)]
return res.reshape(list(category_array.shape) + [n_classes])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment