- The greek letter sigma allows us to describe a range of values, and then add them all together.
- For example, if we want to add the numbers from 1 to 4, we can write:
- This expands to: 1 + 2 + 3 + 4
- The value of n starts at 1 (written under the sigma), and ends on 4 (written above the sigma).
A more complex sum
- In the introductory example, we simply put n after our sigma, however we can write more complex equations too:
- This would expand to:
- If we have a set of numbers, for example: S = [2, 5, 3], then we can sum it with:
- Where |S| is the length of the set, and Sn is the nth value of S.
- This is often simplified to:
numbers = [1,2,3,4]
summed = sum(numbers)
print(summed) # prints 10