Currently, my favorite mathematical operation is the dot product (in data vectors).
A computational/data vector in mathematics is essentially a list of numbers (different from their cousins, the geometric vectors which are defined a bit differently). In linear algebra, we define some interesting operations with vectors.
The first one is the vector addition, in which the sum of the vectors is just the pairwise sum of their elements: [1, 2, 3, 4, 5] + [1, 0, 2, 0, -1] = [2, 2, 5, 4, 4].
The second one, is the vector-constant multiplication, in which we multiply each entry of the vector by a constant: 10 * [1.5, 2, 3, 4] = [15, 20, 30, 40].
And well, it would be natural for us to define a vector-vector multiplication, similar to the addition. However, we have reserved the • symbol for a much more interesting (and in my opinion, useful) operation: The Dot Product
The dot product of two vectors x and y is a number, and it is the sum of the product of their pairwise entries, in other words:
x * y = x[0] y[0] + x[1] y[1] + ... x[n] y[n]
One may wonder: but why? The reason is because a LOT of stuff in mathematics is in this x0 y0 + ... + xn yn form. For instance:
- Sum of all elements of a vector x: x[0] + x[1] + ... + x[n] = x[0] * 1 + x[1] * 1 + ... = x * [1, 1, 1 ..., 1]. Just do the dot product of the vector with one that has all ones
- Sum of the first and last element: x * [1, 0, ..., 0, 1]
- First element minus last element: x * [1, 0, ..., 0, -1]
- Sum of the even indexed elements: x * [1, 0, 1, 0, ...]
- Even indexed - Odd indexed: x * [1, -1, 1, -1, ..., ]
- Last element in the vector: x * [0, 0, ..., 1]
- Mean of the values in the vector: x * [1/n, 1/n, ..., 1/n]
and a lot more. Because of this variety of possible usages, it is currently my favorite math operation. There are also generalizations such as the inner product and matrix-vector multiplication, but that's something for another day









