Like with vectors, there are fundamental operations we can perform on matrices that enable the linear transformations needed for linear algebra. We can again both multiply entire matrices by a scalar value, as well as add or subtract matrices with equal shapes.
A new and important operation we can now perform is matrix multiplication. Matrix multiplication works by computing the dot product between each row of the first matrix and each column of the second matrix. For example, in computing AB = C, element (1,2) of the matrix product C will be the dot product of row 1 of matrix A and column 2 of matrix B. The animation to the right walks through the multiplication of two matrices showing the dot product between each row and column.
An important rule about matrix multiplication is that the shapes of the two matrices AB must be such that the number of columns in A is equal to the number of rows in B. With this condition satisfied, the resulting matrix product will be the shape of rowsA x columnsB. For example, in the animation to the right, the product of a 2x3 matrix and a 3x2 matrix ends up being a 2x2 matrix.
Based on how we compute the product matrix with dot products and the importance of having correctly shaped matrices, we can see that matrix multiplication is not commutative, AB ≠ BA. However, we can also see that matrix multiplication is associative, A(BC) = (AB)C.
Instructions
Here are some optional matrix algebra practice questions!
Matrix Addition Practice Question
Click to see answer
![The answer to the matrix question above. The matrix is [[3, 7], [8, 8]]](https://content.codecademy.com/courses/deeplearning-with-tensorflow/deep-learning-math/matrix_answer1.png)
Scalar Multiplication Practice Question
Click to see answer
![The answer to the matrix question above. The matrix is [[6, 10], [-4, 24]]](https://content.codecademy.com/courses/deeplearning-with-tensorflow/deep-learning-math/matrix_answer2.png)
Matrix Multiplication Practice Question
Click to see answer
![The answer to the matrix question above. The matrix is [[32, 37], [16, 15]]](https://content.codecademy.com/courses/deeplearning-with-tensorflow/deep-learning-math/matrix_answer3.png)