Now I have a vector and I need to sum it and save it, unit by unit, like:
x = [1,1,0,0,0,1,0]
and
sum = [1,2,2,2,2,3,3]
Because of the low efficiency of for-loops, an n-times-n lower triangle matrix comes to me:
com = [1 0 0 0 0 0 0;1 1 0 0 0 0 0;1 1 1 0 0 0 0;1 1 1 1 0 0 0;1 1 1 1 1 0 0;1 1 1 1 1 1 0;1 1 1 1 1 1 1];
By multiplying this com matrix and x, I think I can get sum.
But when n gets big, like 100,000, it cannot be created for taking too much memory(or something like that, which I don't remember precisely).
Therefore, is there a way that I can get this lower triangle matrix by multiplying a col vector and a row vector like:
com = [x1; x2; x3; ... ] * [y1, y2, y3 ...]
PS. is there any other way to accomplish this summing task fast without this lower triangle matrix? Please tell me.
Thanks for viewing and answering!
Best Answer