Help with C4 W1 A1 Optional Ex 7

Hello,
I am having issues with the optional Exercise 7 (distribute_value) question. I am getting the right output when I run the test but also getting an assertion error. Can you kindly help me figure out what I may be doing wrong. Please see below a capshot of the error I am getting. I suspect my issue is with calculating the average from dZ.

This means your code does not work correctly. Do not be fooled by getting some of the tests correct. Partial success means very little.

Tips:

  • “shape” gives you the values for n_H and n_W
  • The average is the dz value divided by the number of elements in shape. Hint: It’s a 2D matrix.
  • For ‘a’, create an all-ones matrix of the correct shape, and multiply it by the average value.

Also notice that there are two different tests there. It looks like you passed the first one, but failed the second one. So that would suggest that you have “hard-coded” something about your implementation so that it happens to match the first test case. Either the dimensions are fixed or perhaps you are referencing global variables instead of the parameters being passed to the function.

Actually the shape of your output must be correct in the second test, so somehow it’s just that there is something wrong with how you are computing the average value that is getting assigned to all the elements. That must be hard-coded somehow. Each element should be 1. in the second test. So what does it turn out to be? That should be a pretty good clue as the nature of your bug.

Thank you very much. As suspected, I was not calculating the average correctly. I have been able to fix the issue with your guidance and the code is working correctly now and I am passing all the tests. Thanks once again for your help.

Thank you very much. As you suspected, I was not calculating the average correctly. I have been able to fix the issue with guidance from both of you and the code is working correctly now and I am passing all the tests. Thanks once again for your help.