19 | 27 | 38 | 24 | 37 |
14 Matrix Operations: Row and Column Sums
14.1 Row Sums
Once we have constructed a matrix, we can do various numerical operations on the matrix to compute all kinds of exciting things. Perhaps the most basic operation that we can do on a matrix is compute its row sums and its column sums.
3 | 3 | 2 | 6 | 5 |
4 | 6 | 9 | 5 | 3 |
9 | 9 | 9 | 3 | 8 |
7 | 9 | 3 | 4 | 1 |
7 | 5 | 7 | 9 | 9 |
Consider the matrix shown in Table tbl-exmat. This matrix is of dimensions \(5 \times 5\) meaning it has five rows and five columns. Let’s call the matrix \(\mathbf{B}\).
The row sums of \(\mathbf{B}\) is written:
\[ \sum_i b_{ij} \tag{14.1}\]
This is called sigma notation. In this formula i refers to the rows of the matrix and j refers to the columns. So the formula says, “to get the row sums, pick a row i, and sum the cells across the columns j.” So for instance, if \(i = 2\), then Equation eq-rowsums turns into:
\[ \sum_2 b_{2j} = 4 + 6 + 9 + 5 + 3 = 27 \tag{14.2}\]
Note that the numbers in the sum are just the number in row two of Table tbl-exmat. The same goes for all the other rows. Note that if we do the row sums of all the rows in the matrix, the result is a row sum vector, containing the total sum for the numbers in each row.
The row sum vector for Table tbl-exmat is:
The first number corresponds to the row sums of the first row, the second to the rows sums of the second row, and so forth.
14.2 Column Sums
The column sums of a matrix work pretty much the same way. In sigma notation the column sum for matrix \(\mathbf{B}\) is written as:
\[ \sum_j b_{ij} \tag{14.3}\]
Note that the main difference between Equation eq-colsums and Equation eq-rowsums is the subscript under the \(\sum\) symbol, which is j instead of i. Equation eq-colsums says: “to get the column sums, pick a column, and then sum each number down the rows.”
So for instance, if \(j = 3\), then Equation eq-colsums turns into:
\[ \sum_3 b_{i3} = 2 + 9 + 9 + 3 + 7 = 30 \tag{14.4}\]
The column sum vector for Table tbl-exmat is:
30 | 32 | 30 | 27 | 26 |
The first number corresponds to the column sums of the first column, the second to the column sums of the second column, and so forth.
14.3 Row and Column Sums of the Symmetric Adjacency Matrix
What happens if we calculate the row and column sum vectors of a symmetric adjacency matrix corresponding to an undirected graph?
Let us go back to the example corresponding to Figure fig-undirected, whose adjacency matrix is show in Table tbl-symmadjmat. The row sum vector of the adjacency matrix is shown in Table tbl-symmsums-1, and the column sum vector is shown in Table tbl-symmsums-2.
A | B | C | D | E | F | G | H | I |
---|---|---|---|---|---|---|---|---|
4 | 3 | 4 | 5 | 3 | 4 | 3 | 3 | 3 |
A | B | C | D | E | F | G | H | I |
---|---|---|---|---|---|---|---|---|
4 | 3 | 4 | 5 | 3 | 4 | 3 | 3 | 3 |
Note two things. For the symmetric adjacency matrix, the row and column sums vectors are identical. So we get the same answer whether we sum the numbers for each row across columns, or for each column down the rows.
But what are these numbers? If you stare at them long enough, you will see that they are familiar, for they are nothing but the undirected graph’s degree set. So, for an undirected graph, the row or column sums of the symmetric adjacency matrix gives us the degrees of each node!
14.4 Row and Column Sums of the Asymmetric Adjacency Matrix
Now what happens if we compute the row and column sums for an asymmetric adjacency matrix? We already saw one such matrix in Table tbl-asymmadjmat corresponding to Figure fig-directed. The row and column sums of that adjcency matrix is shown in Table tbl-asymmsums-1 and Table tbl-asymmsums-2.
A | B | C | D | E | F | G |
---|---|---|---|---|---|---|
2 | 2 | 1 | 1 | 2 | 1 | 2 |
A | B | C | D | E | F | G |
---|---|---|---|---|---|---|
2 | 3 | 1 | 3 | 0 | 2 | 0 |
Note that in contrast to the symmetric case, the row and column sum vectors of the asymmetric adjacency matrix corresponding to a directed graph are different. What’s the difference?
Well if you stare at them long enough, it might dawn on you that the row sum vector corresponds to the directed graph’s outdegree set, and the column sum vector corresponds to the directed graph’s indegree set.
So in the directed case, each of the sum operations that we can perform on the asymmetric adjacency matrix captures a separate graph property, in this case the difference between each node’s indegree (given by the row sums) and each node’s outdegree (given by the column sums). Neat!