Column vector multiplied to a row vector, memory v.s. speed issue

조회 수: 1 (최근 30일)
Xin
Xin 2018년 4월 4일
편집: Stephen23 2018년 4월 4일
Hello everyone. I have a column vector (A) that is left multiplied to a row vector (B). The result is a matrix C=A*B. What I need is the sum of C in each row, that is sum(C,2). However, both A and B are very long vector that makes C rather huge that exceeds memory. Is it possible to bypass the matrix C and get the results sum(C,2) without using a loop, which is a bit slow.
Many thanks
  댓글 수: 6
Birdman
Birdman 2018년 4월 4일
What are the sizes of A and B?
Xin
Xin 2018년 4월 4일
Depending on the data, A can be more than 1e4, and B can be more than 1e6~1e7.

댓글을 달려면 로그인하십시오.

채택된 답변

Stephen23
Stephen23 2018년 4월 4일
편집: Stephen23 2018년 4월 4일
Loop over A, it won't take very long as long as long as the output is preallocated. Replace this:
D1 = sum(A*B,2)
with
N = numel(A);
D2 = nan(N,1);
for k = 1:N
D2(k) = sum(A(k)*B);
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by