Matlab/Octave 1-of-K representation

前端 未结 5 1781
北恋
北恋 2021-01-05 14:58

I have a y of size 5000,1 (matrix), which contains integers between 1 and 10. I want to expand those indices into a 1-of-10 vector. I.e., y contains 1,2,3... and I want it t

5条回答
  •  孤街浪徒
    2021-01-05 15:39

    I think you mean:

    y = [2 5 7];
    Y = zeros(5000,10);
    Y(:,y) = 1;
    

    After the question edit, it should be this instead:

    y = [2,5,7,9,1,4,5,7,8,9....]; //(size (1,5000))
    for i = 1:5000
        Y(i,y(i)) = 1;
    end
    

提交回复
热议问题