문제

I was wondering wether there was a function in std:: (as of c++11) to compute the sum update operation (or 'rolling window sum'). Because I'm not sure how that operation is usually called (and this may be what's preventing me from finding it in std::) the last line of the small code below does what I want (and call the rolling window sum...)

const int n=101, m=n/2;
float a3[n];
float aD[m-1];
std::fill_n(array,m-1,0.0f);

for(i=0;i<n;i++)
    a3[i]=rand();
for(i=0;i<m;i++)
    aD[0]+=a3[i];                   
for(i=1;i<(m-1);i++)
    aD[i]=aD[i-1]+a3[i+m-1]-a3[i-1];  //'here: sum update of a3
도움이 되었습니까?

해결책

The standard library offers no such functionality. You need to implement it yourself.

다른 팁

not sure if this would help you, but there's Boost.Accumulators with its rolling_sum.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top