C3 Week1 Lab 1 compressed image does not show

Hi, the output image of my week1 lab1 shows green. I only run the cell once and I restarted the kernel but the problem still persists. All tcs passed

lab id : cpxdilhd

Hello @Sebastian_James,

  1. Can you add the first two lines like I did in below, and share the print result? Sometimes it can give us some ideas by looking at the array values. You may copy the lines from here.
    print(X_recovered.min(), X_recovered.max())
    Screenshot from 2022-08-11 07-54-12

  2. You passed the tests inside the assignment. Did you submit and pass the grader?


Hi this is the output, btw I did submit and pass the grader

Hello @Sebastian_James, so apparently the centroids has a problem because it has many np.nan values, normally it should contain only numbers. Now, it is either the exercise 1 or 2 has a bug in the code that neither the grader nor the tests are able to catch, or something in the notebook but outside of the exercise has been changed.

For the latter case, it is simple to rule out by getting a new copy of the assignment, copy your exercise codes back and run again. If you would like to try this way, you may get a new copy by following these steps which will ask you to rename your current notebook so that the system will give you a new copy.

For the former case, it will take some time to debug, can you try it?


Sebastian, debugging is a daily task for anyone who codes. I am not sure about your experience in this, but below is how we can start with, please ignore these if you have your own way :slight_smile:

  1. centroid has a problem, and if we look back, run_kMeans(...) generated it

  2. Going into run_kMeans(...), it uses our exericse 1 and 2’s code in these lines:
    idx = find_closest_centroids(X, centroids)
    centroids = compute_centroids(X, idx, K)

  3. if we have ruled out the possibility of something outside of the exercises were changed, then the only chance is from those 2 lines. If I were you I would add
    print('find_closest_centroids', idx) and
    print('compute_centroids', centroids)
    respectively right after the two lines, so that as the code runs, I can keep monitor the print results and see which one goes wrong FIRST. The key is centroids should not contain any np.nan, whereas idx should be a non-negative integer between 0 and 15.
    (P.S. you may want to stop running the cell as soon as something wrong is printed)

  4. If you can identify which of the 2 exercises have a problem, then it’s time for you to figure out why.

Good luck!

1 Like

thank you very much! I will try

Hello, I am also having the same error. I passed the tests, but I do not have any np.nan values.

@Charles_Richards, please also print these after the two print lines, and share the results


@Charles_Richards, please also run the notebook from top to bottom AGAIN, add the 3 new print lines in the way I asked, and share the print results together with the compressed picture you get this time.

Sorry, I fixed the problem. Using the np.square function vs **2 gives different results. **2 will let you pass the first test but will change the expected results from [0,2,1] to [0,1,1]. With that in mind, I would have gotten the np.nans, but I also realized that I was truncating numbers using an int array instead of a float. Thank you for your assistance

1 Like