Data Analysis with Python: From Raw Data to Real-World Insights
BOOK 2 · MATHEMATICS & STATISTICS · CHAPTER 4

Chapter 4 exercises: Linear Algebra and Matrix Operations

On this page

Attempt these tasks before opening the worked answers. Use the chapter experiment notebook, or import NumPy as np and Pandas as pd in your own notebook. Retain your first attempt and explain each correction.

B2-04-E01 · Check a linear solution

Solve Ax=b and verify the residual with a numerical tolerance.

A=np.array([[2.,1.],[1.,3.]])
b=np.array([8.,9.])
One hint after an attempt

Verify by substitution.

B2-04-E02 · Recognize dependent columns

Find the matrix rank and explain why two independent coefficient effects cannot be identified from these columns alone.

X=np.array([[1.,2.],[2.,4.],[3.,6.]])
One hint after an attempt

Express one column as a multiple of another.

B2-04-E03 · Use least squares

Fit an intercept and slope using lstsq, then check the fitted values.

x=np.array([1.,2.,3.])
y=np.array([3.,5.,7.])
One hint after an attempt

Build a column of ones for the intercept.

Reflect and get feedback

Explain one result without looking at the code. Identify one boundary case that would change your method. An optional tutor prompt is: “Here is my attempt at B2-04-E03. Give one hint about the violated assumption; do not give the solution yet.” Then use the worked answers.

Teaching edition · verified experiments · PDF and EPUB editions not generated.