Taking Linear Algebra for ML, Week 4 Assignment: Webpage navigation model and PCA giving me trouble

I have a solid background in python, I figured out how to do covariance matrices etc from the lecture but I can’t figure out what Exercise 3 is asking to create the function def center_data(Y):

I understand I need the mean of each column to get variance but that seems like a whole process of parsing through the huge numpy array.

I might be overthinking what the programming question is asking.

In center_data(), you need to write four lines of code. Three of them use numpy functions.

  1. use mean over axis 0.
  2. use np.repeat over the mean vector, using Y.shape[0] to get the ‘n_observations’ value.
  3. reshape the mean_matrix to be the same shape as Y. Read the hint comment.
  4. compute X as the difference between Y and the mean_matrix.
2 Likes

I interpret it as needing like 4096 means
To calculate the column mean, don’t I need to loop through the i-th column….of all 55 rows?

Numpy does that for you, when you specify axis=0.

1 Like

Thank you. Numpy really does handle a lot of things for us, wow.

1 Like