Different Values From Expected Values

Hi,
I followed hints, but the same code that I wrote gets different value from expected values.
I couldn’t find the problem.

{assignment code removed by mentor as we can’t share it here}

When I divide by 2m instead of m, it gets closer value but not the same.
{code removed by mentor}

Because of this problem, I can’t pass upcoming tests :

Hi @Ahmet_Mete_EROL ,

Please refer to the hints on how to calculate f_wb, particularly how the each of ‘For’ loop’ is structured. Python uses indentation to structure code block, make sure your code has the correct indentation to keep the flow of the logic in the right way.

DISCLAIMER: I’m no Python expert so I’m guessing there’s a more efficient way to do this with breakpoints but the following debug process worked for me.


I ran into a similar problem, which is related to the execution order of the for loop commands (the impact of indenting can be hard to fully grok when you can’t view the related step by step outputs).

So I found it helpful to put in print statements along the way to see what exactly was happening with each for loop.

I recommend:

  1. Create a copy of this lab to play around with as you’ll need to enter additional cells (and if you try to submit that, it could create a problem) → so you’ll figure out how to make this work in your ‘working copy’ of the lab but then submit clean code without all the debug and print statements
  2. Put in a print(f’\n’) after the for i in range(m): to separate results
  3. Use a print(f’X[{i}][{j}] = {X[i][j]}') in the appropriate place to see how the input array is structured
  4. print(f’dj_db_{i} : {dj_db_i: 0.5e}') to see what’s going on there at each step of the loops
  5. print(f’running total of dj_db : {dj_db: 0.5e}') similarly
  6. print(f’dj_dw_{i}{j} : {dj_dw_ij}') similarly
  7. print(f’running total of dj_dw : {dj_dw}') similarly

After 100 iterations you just need to divide by 100 and then you can get an idea of where things went wrong. You can play around with your for loop indentation and see the results to get a better understanding of what may be going wrong.

Hope this helps.

1 Like

Hello @bill.leece, great suggestion indeed! I always find printing a good way to keep track of the program and to spot where it starts to go wrong.

Raymond

Thank you for your kind returns. I figured it out, as you said.