C1W4_Assignment Index Errors

Hello all,

I seem to be having a size/shape/indexing error for exercise 3. I used np.shape(Y)[0] to get the number of n_observations for any matrix Y. Are there any suggestions for me to try or consider? For exercises 4 and 5 I also get IndexErrors.

Thank you for the help,

You don’t need to know n_observations. The hint in the code tells you to use the mean function and axis = 0.

Thank you! The hint helped me for sure, but It also doesn’t seem like I am calculating X well. I have a new error from my np.reshape() line

Hi @plausible. Your latest error means the shape of the original array could not be reshaped into a 55x4096 array. This is because the product of dimensions in the target shape is 55*4096=225280, which is not equal to 12390400.

Most likely, the shape of the mean_vector or the mean_matrix is incorrect. When creating the mean_vector, be careful which axis argument you pass in. And when creating the mean_matrix, you will need to repeat it n_observations times.

Your vector size is exactly 55 times too large.

When you use the np.repeat() function, you do need to know Y.shape[0]. My mistake earlier in this thread.

Thank you both for your help! I was able to complete the exercise.

2 Likes