Matrices (Pt. 2): MM
Last updated
Last updated
This is probably where 💩 gets slightly difficult, but it is also where the crux of all data transformation happens 😌. I will firstly walk-through the mechanical operation, and then subsequently a few ways to think about it in the next page.
Each row of matrix evaluates with its corresponding column vector
We can break-up the above operation to help assist in understanding.
A(1, 1) multiplies with B(1, 1).
A(1, 2) multiplies with B(2, 1).
The result of C(1, 1) is the summation of elements involved in the interaction from row 1 of Matrix A and col 1 of Matrix B
A(2, 1) multiplies with B(1, 1).
A(2, 2) multiplies with B(2, 1).
The result of C(2, 1) is the summation of elements involved in the interaction from row 2 of Matrix A and col 1 of Matrix B
Now, try to perform the following problem before revealing its answer! 👍
Each row of matrix evaluates with each of its respective column vector.
Number of columns (n) of left matrix must be equal to number of rows (m) of right matrix
Let us break up this problem like we've had previously. 💔
We begin with the first row of the left-matrix, and
Multiply it with the first column of the right-matrix, with
The output element thus occupying the space (1, 1)
With the previous example laid out, you might question "What would happen if there are not enough elements in my right-matrix to interact with my left?".
With that being a valid question, math simply answers back with a "you can't" 🥁. Hence, the size of both matrices and the non-commutative property (discussed at next page) are important to ensure valid operations.
To recap, we would require
The same amount of columns in the left-matrix, to
the rows of the right-matrix
For example, a left-matrix of size m x n, has to interact with a right-matrix of size n x o, with m and o being any integers greater than or equals to 1.
Finally, the following might be a trivial, but yet a useful trick to find the size of the output vector.
As it is a requirement for "n" (value 2) to be the same,
With the values of "m" (value 2), and
"o" (value 1),
The size of output variable of m x o (2 x 1) can be seen
The output matrix size is the rows of the left-matrix, by the columns of the right-matrix (m x o).
To recap from the previous page, an element has the notation of a(i,j),
where i is the row number,
and j is the column number
Supposed the fact that the above matrix is the output matrix X in the operation (a . b = x),
What then were the factors of A and B used for the computation of a particular element in X?
You may then recall that we previously used the count of row numbers of the left-matrix, and the count of column numbers of the right-matrix to determine the output matrix size.
Similarly, for each output element x(i, j), its factors are the resultant interaction between the
"i-th" row of the left matrix, and
the "j-th" column of the right-matrix.
This would otherwise be also the standard way to think about matrix multiplication, with:
The following question helps illustrates the discussion.
Let's say we arbitrarily wanted to check the value and the method we obtained x(2, 3).
How do we go about doing so? Easy!
We can do so simply via the 2nd row of the left-matrix, and the 3rd column of the right-matrix.
The output matrix X can be alternatively thought of as
A combination of 3 separate columns, from
Its corresponding column in right-matrix B,
Multiplied by matrix A
Alternatively, the output matrix X can be alternatively thought of as
A combination of 3 separate rows, from
Its corresponding row in left-matrix A,
Multiplied by matrix B