This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Is there a function to do accumulated sum of a vector?

Tags: None
(comma "," separated)
coolcat
Registered Member
Posts
20
Karma
0
OS
Given a vector v,
-- VectorXd v(100);
-- v.setRandom(100, 1);

I'd like to have another vector comprised of accumulated sum of the vector, that is
-- VectorXd v_accum(100);
-- v_accum << v(0), v(0) + v(1), v(0) + v(1) + v(2), ....., v(1) + v(2) + v(3) + ... + v(98) + v(99);

Although there is a routine sum(), I can't find the efficient routine for doing accumulated sum.
Is there any ?
Or could you suggest sum efficient method to do it?

Thanks in advance.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
This is also often called a "prefix sum", but there is no such function in Eigen yet.


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]