A cumulative sum tracks a running total, not a running average

A sequence can describe separate contributions, one at each position. A cumulative sum changes the question. Instead of showing only the contribution at a position, it shows the total of all contributions from the beginning through that position.

This operation is useful when the path of an accumulation matters. It preserves an intermediate result at every step rather than returning only one final total. Those intermediate results are connected, however. They are not independent observations, and they should not be read as averages unless another calculation supplies the required division.

Each position includes everything that came before

Consider four contributions: two, three, one and four units. The first running total is two. Adding the second contribution gives five. Adding the third gives six, and adding the fourth gives ten. The cumulative sequence is therefore two, five, six and ten.

The four inputs produce four running totals. At the third position, six means the sum of the first three contributions. It does not mean that the third contribution was six. That contribution was one, which moved the running total from five to six.

Four contributions and their running totals

The last running total equals the sum of all four inputs in this exact arithmetic example. The earlier running totals describe shorter prefixes of the same sequence. The first prefix contains one contribution, the next contains two, and so on.

A running average needs a second operation

The average of the first three contributions is six divided by three, which equals two. The cumulative sum at that position is six. Confusing these quantities would turn a total into a value per contribution without performing the necessary division.

To obtain a running average over the sequence, divide each running total by the number of contributions included at that position. In our example, the divisors are one, two, three and four. The resulting averages are two, two and a half, two, and two and a half.

This count-based rule assumes that each contribution receives equal weight. If the values have different weights, the numerator and denominator need to reflect those weights. A plain cumulative sum does not decide the appropriate averaging method.

The intermediate path depends on the order

Rearrange the same contributions as four, one, three and two. The running totals become four, five, eight and ten. The final total remains ten in exact arithmetic, but the route to that total changes.

This is why order matters when presenting cumulative results. The path may describe time, distance, position in a process, or another declared ordering. Reordering the rows without explaining it can change the apparent pattern even though the set of contributions is unchanged.

It is also important to identify the starting point. These running totals begin from zero before the first contribution. If a separate starting balance is needed, it must be added explicitly. The cumulative operation does not infer an earlier balance from context.

Signed contributions can reduce a running total

The increasing pattern in the first example comes from using only positive contributions. A cumulative sum is not required to rise at every step. A negative contribution reduces the next running total, while a zero contribution leaves it unchanged.

For instance, the contributions four, negative one and two produce running totals four, three and five. The operation is still addition at each step. The direction of movement follows the sign of the contribution rather than a rule that cumulative values must always increase.

A chart should therefore distinguish the original contributions from the accumulated values. Their units may be the same, but their meanings differ. One describes the separate inputs; the other describes the total reached after including them.

The axis and number type remain part of the definition

In NumPy, cumsum can operate along a chosen axis. For a table, accumulating across each row answers a different question from accumulating down each column. Without an axis argument, the operation uses the flattened array rather than preserving a separate accumulation for each row.

The number type also matters. Integer accumulation can exceed the representable range of its type. Floating-point accumulation can introduce rounding differences, so its final entry need not exactly match a separately computed sum that uses another summation method.

A clear description names the input contributions, their order, the starting point and the axis. With those details visible, a running total remains an accumulation over prefixes, rather than being mistaken for a separate contribution, an average or a quantity whose starting conditions were never supplied.

Academia Master Trader shares educational material about numerical structures, operations and data interpretation at academiamastertrader.com.br.

Aprenda