Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
150 views
in Technique[技术] by (71.8m points)

arrays - How come these two matrices are not equivalent?

Assume we have a 3 dimensional array F and 2 dimensional matrix S. First I find a matrix Y which is F multiplied by S. Then I try to find an estimate of F (lets call it F_est) from Y as sanity check in my code. Can anyone see a flaw in logic, I dont seem to know why F_est is not exactly F.

F= randn(2,4,600);
S= randn(4,600);
for i =1:size(F,1);
    for j=1:size(F,2)
        for k= 1:size(F,3)
            Y(i,k)= F(i,j,k) * S(j,k);
        end
    end
end

for i =1:size(F,1)
    for j=1:size(F,2)
        for k= 1:size(F,3)
            F_est(i,j,k)= Y(i,k) / S(j,k);
        end
    end
end

then I try to see if F_est - F is zero and it is not. Any ideas. Much aprreciated.

**** EDIT after comments

Based on the answers I got I am wondering if the code below makes any sense?

for k=1:size(F,3)
Y(:,k) = squeeze(F(:,:,k)* S(:,k)
end

Am I able to recover F if I have Y and S?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

When you create Y, you are replacing its values continuously. For any value of pair of i,k you are overwriting Y jtimes!

Those 2 codes are not equivalent, as F_est(i,j,k) computed only once, but you have Y(i,k) j times.

I don't know what you are trying to do, but a multiplication of a 3D matrix by a 2D matrix is not defined, and its not a 2D matrix


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...