Created
October 11, 2013 18:31
-
-
Save zygmuntz/6939718 to your computer and use it in GitHub Desktop.
One way of doing one-hot encoding in Matlab
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
% y is a vector of labels | |
y_one_hot = zeros( size( y, 1 ), n_classes ); | |
% assuming class labels start from one | |
for i = 1:n_classes | |
rows = y == i; | |
y_one_hot( rows, i ) = 1; | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
y_one_hot = full(ind2vec(y',num_classes)) is a clean way to do this.