Matrix X has 2 rows, 3 columns (2x3), and matrix Y has 3 rows, 2 columns.
-To determine the final dimensions of the resultant matrix Z, take the number of rows from matrix X (2) and number of columns from matrix Y (2).
+To determine the final dimensions of the resultant matrix Z, take the number
+of rows from matrix X (2) and number of columns from matrix Y (2).
For the algorithm, assign indeces to matrices as follows:
Index | 0 1 2 3 |
Mat Z | 52 58 100 112 |
-The method usually taught in linear algebra course to students is the following:
+(Start with the first row, then assign index left-to-right, top-to-bottom.)
-1. Start with the first row of the first matrix, and first column of the second matrix.
-2. Multiply each element in the row by each element in the column, and sum the result.
-3. Store result in the first row, first column entry.
+The method usually taught in linear algebra course to students is the
+following:
-Equation: (TODO)
+1. Start with the first row of the first matrix, and first column of the
+second matrix.
+2. Multiply each element in the row by each element in the column, and sum
+with the current value of the result matrix element (multiply-add-accumulate).
+Store result in the first row, first column entry.
+3. Move to the next column of the second matrix, and next column of the result
+matrix. If there are no more columns in the second matrix, go back to first
+column (second matrix), and move to next row (first and result matrices).
+If there are no more rows left, result matrix has been fully computed.
+4. Repeat step 2.
+4. Move to the next row of the first matrix, and next column of the second matrix.
+
+This for-loop uses the indeces as shown above
+
+ for i in range(mat_X_num_rows):
+ for k in range(0, mat_Y_num_cols):
+ for j in range(0, mat_X_num_cols): # or mat_Y_num_rows
+ mat_Z[i][k] += mat_X[i][j] * mat_Y[j][k]
- A(i, j) * B(j, k) = C(i, k)
Calculations:
| 3 4 5 | * | 8 9 | | 100 112 |
| 10 11 |
+
+
## Appendix
### Links