Last active
June 8, 2021 07:19
-
-
Save yuki-inaho/5be2ac911847ad253bdf1bf5af165369 to your computer and use it in GitHub Desktop.
categorical-labelled mask -> one-hot type expression
This file contains hidden or 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 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