P2-2.2 Sigma and Repeated Computation¶
Section ID:
P2-2.2Version:v2026.09.08
Sigma is notation that compresses the addition of multiple values.
Sigma may look unfamiliar, but the core is simple. It means that several values should be added repeatedly. In AI documents, it appears frequently when explaining the sum over many data points, means, sums of loss, and batch-level computation.
Repetition Range and Terms¶
| Criterion | Why It Matters |
|---|---|
| Sigma is compressed notation that tells you to repeat addition of the same shape | It lets you reread an unfamiliar symbol as computational structure. |
| The index is the name that distinguishes which item is being added | It keeps you from losing the repeated position. |
| Sigma appears often in AI documents because many data points are gathered into sums, means, and losses | It shows why statistics and loss aggregation share the same notation. |
Parts of Sigma Notation¶
Sigma notation specifies both the repetition range and the term to add.
This one line contains four pieces of information.
- the large symbol \(\sum\): the command to add
- the lower part \(i=1\): where the repetition starts
- the upper part \(n\): where the repetition ends
- the right-hand term \(x_i\): what is added each time
If you separate it like this, sigma stops looking like a suddenly appearing difficult symbol and starts reading like a sentence that writes repeated addition briefly.
- Start
ifrom 1. - Repeat until
ireachesn. - Add
x_ieach time.
So sigma is not only a symbol that says "sum." It is notation that also writes what is gathered, in what order, and over what range. This viewpoint is also useful when you recall a loop in code.
That does not mean sigma is exactly the same thing as a code loop. Mathematical notation shows computational structure in compressed form, while code unfolds it into actual execution procedure.
Expanding a Simple Sigma Expression¶
The best way to read sigma is to expand a short expression directly.
This expression means that as i changes from 1 to 3, you add i itself.
So it can be expanded as follows.
If you look at a form closer to AI documents, you get the following.
If \(x_1=2\), \(x_2=4\), and \(x_3=6\), then you compute it as follows.
If you go on to compute the mean, it becomes the following.
Indices and Loops¶
In sigma, i is the index. The index is the name that tells you which position you are looking at now.
Here, each part is read as follows.
i: the index that marks the repeated position1: the starting positionn: the ending positionx_i: the i-th valueΣ: the sign that tells you to changeiand add values
In code, it looks roughly like the following.
the list values containing four values. the total sum 10 is printed.
Example execution result:
The i in the formula and the value in code are not completely the same thing. But they connect in that both indicate the current item being looked at during repetition.
Sums and Means¶
A mean is a good example for understanding sigma. When you add all the values and divide by the count, you get the mean.
Written with sigma, it is compressed as follows.
This expression can be read as follows.
- Change
ifrom 1 tonand add all thex_i. - Divide that sum by
n.
In code, you can write it as follows.
the list values containing four values. the mean value 2.5 is printed.
Example execution result:
If you use a NumPy array, it becomes shorter.
the NumPy array values that holds four values. the mean value 2.5 is printed.
Example execution result:
Here, values.mean() performs the mean calculation internally. It does not write sigma directly, but the structure of gathering many values and computing over them remains the same.
Per-Sample Loss and Mean Loss¶
In machine learning, loss expresses numerically the gap between the model output and the reference value. If there is only one data point, then only one loss needs to be computed.
But in real learning, there are many data points. For each data point, there is a prediction and a target, and for each data point a loss is created.
If you simply add the whole loss, it becomes the following.
Written with sigma, it becomes the following.
Mean loss is that sum divided by the number of data items.
In code, it can be seen as follows.
the prediction list predictions and the answer list targets. the average of the sample losses is printed.
Example execution result:
This example simplifies real deep-learning training code. The key point is that, because there are many data items, the same computation is repeated and the repeated results are summed or averaged.
Aggregating Batch Loss¶
In deep learning, it is common not to process data one by one, but to process them as a batch. Inside one batch are many samples, and the model creates one output for each sample. Here, batch is the bundle of many input data items, prediction is the model output for each input, loss is the gap between each output and reference value, and mean_loss is the mean of the losses inside the batch.
Even here, the sigma viewpoint remains the same. You inspect each sample inside the batch, compute the loss for each sample, and then sum or average those losses.
Loops and Array Operations¶
For the three samples above, the squared errors are approximately 0.04, 0.01, and 0.25. Their mean is (0.04 + 0.01 + 0.25) / 3 = 0.1. NumPy applies subtraction and squaring at each array position, then computes the mean with mean().
The inputs are prediction and target arrays. The code prints their mean loss.
Example execution result:
The loop is not visible, but the repeated computation has not disappeared. The array computation has only changed the expression so that many values are handled at once.
Checklist¶
- Can you explain sigma as compressed notation for repeated addition?
- Can you distinguish the index, the start position, the end position, and the term to be added?
- Can you explain a mean both with sigma notation and with code?
- Can you explain the flow of summing or averaging losses over many data items?
- Can you explain that loops and array computation can connect to sigma notation?
- When sigma appears, can you unfold it by asking,
what is being added, and how many times? - Can you explain why sigma helps later when reading statistics, loss calculation, batch computation, and optimization?
- Can you expand a simple sigma expression into terms and compute the sum or mean?
- Can you connect mean, loss, and batch computation by explaining that they share the same aggregation structure through sigma and code?
Sources and References¶
- Marc Peter Deisenroth, A. Aldo Faisal, Cheng Soon Ong, Mathematics for Machine Learning, Cambridge University Press, 2020, checked on 2026-07-19.
- Ian Goodfellow, Yoshua Bengio, Aaron Courville, Deep Learning, MIT Press, 2016, checked on 2026-07-19.
- Charles R. Harris et al., Array Programming with NumPy, Nature, 2020, checked on 2026-07-19.
- NumPy Developers, numpy.sum, NumPy User Guide, checked on 2026-07-19. This official reference explains summing array elements and sums along axes.
- NumPy Developers, numpy.mean, NumPy User Guide, checked on 2026-07-19. This official reference supports the mean calculation and
mean()examples.