Octave中的1-K编码 [英] 1-of-K coding in Octave
问题描述
y
,比如说$ b $ pre $
y = [1 ; 2; 3; 1; 3]
我想要一个矩阵
Y = [1 0 0
0 1 0
0 0 1
1 0 0
0 0 1]
我可以用
来构造一个K矩阵, pre> Y = [];
Y = [Y y == 1];
Y = [Y y == 2];
Y = [Y y == 3];
但是当我尝试用来构造
循环,
Y = [];
for i = unique(y),
Y = [Y y == i];
endfor
出错:
错误:mx_el_eq:不一致参数(op1是5x1,op2是3x1)
我甚至不理解错误信息。我的错误在哪里?
好的,找到它了。我希望教程告诉我这个。
Y = [];
for i = unique(y)',
%^
%------------- /
Y = [Y y == i ]。
end
显然, I'm trying to get a binary one-of-K coding of a integer vector in Octave. I've got a vector and I want a matrix I can construct the one-of-K matrix by hand with But when I try to construct it with a something goes wrong: I don't even understand the error message. Where's my mistake? Ok, found it. I wish the tutorial had told me this. Apparently, 这篇关于Octave中的1-K编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!从一个向量的列循环从左到右,
unique
返回一个列向量,所以nonconformant arguments (5×1)和 unique(y)
(3 x 1)。$ / $ c y
, sayy = [1 ; 2 ; 3 ; 1 ; 3]
Y = [1 0 0
0 1 0
0 0 1
1 0 0
0 0 1]
Y = [];
Y = [Y y == 1];
Y = [Y y == 2];
Y = [Y y == 3];
for
loop,Y = [];
for i = unique(y),
Y = [Y y == i];
endfor
error: mx_el_eq: nonconformant arguments (op1 is 5x1, op2 is 3x1)
Y = [];
for i = unique(y)',
% ^
% -------------/
Y = [Y y == i];
end
for
loops through the columns of a vector from left to right and unique
returns a column vector, so the "nonconformant arguments" are y
(5×1) and unique(y)
(3×1).