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

best way to compute cumulative sum (cumsum)?

Tags: None
(comma "," separated)
mitmatt
Registered Member
Posts
1
Karma
0
Is there a convenient way to compute cumulative sums in Eigen, like the cumsum functions in Matlab and NumPy?

A vector cumsum would be something like:

Code: Select all
In [1]: a = arange(5)
In [2]: a.cumsum()
Out[2]: array([ 0,  1,  3,  6, 10])


or along a specific axis of an array:

Code: Select all
In [3]: A = arange(15).reshape((-1,3))
In [4]: A
Out[4]:
array([[ 0,  1,  2],
       [ 3,  4,  5],
       [ 6,  7,  8],
       [ 9, 10, 11],
       [12, 13, 14]])
In [5]: A.cumsum(0)
Out[5]:
array([[ 0,  1,  2],
       [ 3,  5,  7],
       [ 9, 12, 15],
       [18, 22, 26],
       [30, 35, 40]])


If there isn't an easy existing method, is there a natural way to extend Eigen with such an operation?

(By the way, thanks for the amazing library, and apologies if this is a newbie question!)
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS


Bookmarks



Who is online

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