Back

Summation of Vectors and Matrices

Definition

Summation of a matrix or vector means adding elements either:

  • Column-wise (most common in data analysis)
  • Row-wise

A powerful method uses a vector of ones to compute sums and averages using matrix multiplication.


Key Points

  • A matrix ( X_n×mX\_{n \times m} ) has:

    • ( nn ) rows (observations)
    • ( mm ) columns (features)
  • To compute column sums:

    1nTX1_n^T \cdot X

    where ( 1nT=[1 1 1 ... 1]1_n^T = [1\ 1\ 1\ ...\ 1] ) (row vector of size (1 \times n))

  • To compute column averages:

    1n1nTX\frac{1}{n} \cdot 1_n^T \cdot X
  • This works because:

    • Multiplying by a vector of ones adds all rows together

Example / Code

Example 1: Matrix Summation and Average

Given:

X=[20003752500473300058510004651000281500170200000]X = \begin{bmatrix} 2000 & 3 & 75 \\ 2500 & 4 & 73 \\ 3000 & 5 & 85 \\ 1000 & 4 & 65 \\ 1000 & 2 & 8 \\ 1500 & 1 & 70 \\ 2000 & 0 & 0 \end{bmatrix}

Column sum:

17TX=[1450019376]1_7^T \cdot X = \begin{bmatrix} 14500 & 19 & 376 \end{bmatrix}

Average:

1717TX=[2071.432.7153.71]\frac{1}{7} \cdot 1_7^T \cdot X = \begin{bmatrix} 2071.43 & 2.71 & 53.71 \end{bmatrix}

Example 2: Using Ones Vector

[111111][859182829292789091929575978576909080]    [524543496]\begin{bmatrix} 1 & 1 & 1 & 1 & 1 & 1 \end{bmatrix} \cdot \begin{bmatrix} 85 & 91 & 82 \\ 82 & 92 & 92 \\ 78 & 90 & 91 \\ 92 & 95 & 75 \\ 97 & 85 & 76 \\ 90 & 90 & 80 \end{bmatrix} \implies \begin{bmatrix} 524 & 543 & 496 \end{bmatrix}

Average:

[87.390.582.6]\begin{bmatrix} 87.3 & 90.5 & 82.6 \end{bmatrix}

General Formula

1n1nTX\frac{1}{n} 1_n^T X


Practice Matrix

A=[178151289162391017341011184511121956121320671314217]A = \begin{bmatrix} 1 & 7 & 8 & 15 & 1 \\ 2 & 8 & 9 & 16 & 2 \\ 3 & 9 & 10 & 17 & 3 \\ 4 & 10 & 11 & 18 & 4 \\ 5 & 11 & 12 & 19 & 5 \\ 6 & 12 & 13 & 20 & 6 \\ 7 & 13 & 14 & 21 & 7 \end{bmatrix}

Average:

1717TA\frac{1}{7} \cdot 1_7^T \cdot A

Explanation

  • The vector of ones acts like a “sum operator”.

  • When you multiply:

    • Each column is summed independently
  • Dividing by ( nn ) gives the mean of each column

This method is widely used in:

  • Machine Learning (feature averaging)
  • Statistics (mean calculation)
  • Data preprocessing

Output (if any)

  • Output of summation: row vector (1×m)(1 × m)
  • Output of average: row vector (1×m)(1 × m)

Common Mistakes

  • ❌ Using wrong dimension for ones vector → Must match number of rows

  • ❌ Dividing by wrong value → Always divide by number of rows ( nn ), not columns

  • ❌ Arithmetic errors in summation → Double-check sums carefully

  • ❌ Confusing row-wise vs column-wise operations


Short Exam Notes (very concise revision points)

  • Column sum: ( 1nTX1_n^T X )
  • Column mean: ( 1n1nTX\frac{1}{n} 1_n^T X )
  • ( 1n1_n ): vector of ones
  • Output is always 1×m1 × m
  • Used for fast matrix-based averaging