Week 4 c1 w4

Hey guys,

I am facing a little trouble with the lab assignment for Week 4. Specifically exercise 3 on the center_data function.

So I filled out the function and it seems to work because the cat picture in the code block right below generates correctly. However, the unit tester says 1 test passed and the other failed and the grader gives me a zero for the exercise.

I am suspicious that it is not the same cat though, and I don’t know if that makes a difference or if all of the operations we have done up to then have scrambled the order of the images.

Here is what I have so far for the function:

# Graded cell
def center_data(Y):
    """
    Center your original data
    Args:
         Y (ndarray): input data. Shape (n_observations x n_pixels)
    Outputs:
        X (ndarray): centered data
    """
    ### START CODE HERE ###

       # mentor edit: code removed

    ### END CODE HERE ###
    return X

Please do not share your code on the forum. That’s not allowed by the Code of Conduct.

Just post screen capture images of any error messages or asserts.

It’s no problem, I’ll edit your post to remove the code.

I’ll reply further as to your specific issue a bit later.

Your code only does part of what is required here: you compute the mean, but that’s not the end of the story, right?

Also note that they make things a lot more complicated than they need to be in the instructions for this section. If you just use keepdims = True when you compute the mean as a vector, then don’t need to use repeat and reshape: just take advantage of “broadcasting” when you subtract the mean to get the final “centered” data.

Got it! Thanks a lot man. I was pulling my hair out.

1 Like

It has been resolved, thanks. Also sorry about posting my code, will avoid that in the future.

1 Like

It’s great news that you found the solution based on those hints!

The “meta” lesson here is that when you’re just 100% sure that your code is right but it still fails, it’s always worth just taking a couple of deep calming breaths and then having a careful look at the instructions again with the thought in mind that maybe you missed something the first time through. :nerd_face:

1 Like