我想在MATLAB中将onehot数组转换为整数值数组。给出:
Y = 1 0 0
0 1 0
0 1 0
我想回来:
new_y = 1
2
2
答案 0 :(得分:5)
您可以使用find
并仅返回列索引,如此
Y = [1 0 0; 0 1 0; 0 1 0];
[~, new_y] = find(Y); % output: [1; 2; 2] is the col indices of your 1s
同样,如果您的输入是转置
,则可以返回行索引[new_y, ~] = find(Y); % output: [1; 2; 3] is the row indices of your 1s
答案 1 :(得分:1)