Data Lab 1: Elementary Operations on Matrices

In this module, you will be introduced to some fundamental concepts in linear algebra that form the foundation of many data science and AI models you will encounter as you progress through your study program. Rather than teach it as a core mathematical topic, the aim of this module is to provide you with exposure to key topics in linear algebra that are essential for data science.

Today's learning objectives

  • Understand how to implement elementary linear algebra operations in Python

1. Elementary operations on Matrices

1) Compute the determinant and transpose (by hand) of the following matrices. i.


ii.

iii.

iv.

2) Use Python and Numpy, in particular numpy.linalg.det and .T to check if your answers are correct.

3) Compute the element-wise product of the following two matrices.

i.


ii.


4) Use Python and Numpy, in particular .multiply and * to check if your answers are correct.

5) Compute the matrix (dot) product (by hand) of the following two matrices.

i.


ii.


6) Use Python and Numpy, in particular .dot and @ to check if your answers are correct.

7) Compute the matrix inverse (by hand) of the following matrix.

hint: clicky

8) Use Python and Numpy, in particular numpy.linalg.inv to check if your answers are correct.

9) Create a greyscale pixel image using numpy, and rotate the image clockwise by 90 degrees, only using linear algebra operations.

hint: reuse the pixel art you created in block A.

10) Given the following linear algebraic equation: B = (XTX)-1XTY. Write a psuedocode for a function which will take two matrices X and Y as input, and return B.

As an additional challange, replace the matrix operations in your psuedocode with their numpy equivalents.