cumsum
Builtin index · Collections & strings
result = cumsum(x)
Input: x · Output: result
What it is
x is a numeric Vec or Signal; a boolean mask counts as 0/1, so cumsum(x > c) is a running count.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = cumsum(x) | x Vec, Signal, or booleannot documented yet | result Signal | Returns the running sum, same type/length as x; a Signal input stays a Signal with the same Fs. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
ys = [3, 1, 4, 1, 5]
print(contains(ys, 4)) # true
print(indexof(ys, 4)) # 2
print(cumsum(ys)) # [3, 4, 8, 9, 14]
print(numel(ys)) # 5
output
true 2 [3, 4, 8, 9, 14] 5
from collections-strings
fs = 1000
n = 0:1:511
t = n / fs
x = sin(2*pi*20*t) + 0.2*randn(512, seed=4)
r = acf(x, max_lag=50)
below = find_peaks(-abs(r - 1/e))
print("acf[0] = {r[0]}, acf drops below 1/e near lag {below[0]}")
h_tone = hurst_exponent(x)
h_walk = hurst_exponent(cumsum(randn(512, seed=5)))
print("hurst (periodic+noise) = {h_tone}, hurst (random walk) = {h_walk}")
output
acf[0] = 1, acf drops below 1/e near lag 9 hurst (periodic+noise) = 0.71599, hurst (random walk) = 0.998318
from signal-processing