C1W2 Assignment - back_substitution wrong output

Hi,

code for back_substitutions runs without errors… however, unit test results are as follows. Unsure as to what I am doing wrong.

Wrong output for test case check_null_matrix.
Expected:
[5 6 7].
Got:
[0 0 7].
Wrong output for test case check_matrix_1.
Expected:
[-0.33333333 -1.33333333 2.33333333].
Got:
[0. 0. 2.33333333].
Wrong output for test case check_matrix_2.
Expected:
[0.7857143 1.64285714 0. ].
Got:
[0. 0. 0.].
Wrong output for test case check_matrix_3.
Expected:
[19. -2. 1.].
Got:
[0. 0. 1.].
0 Tests passed
4 Tests failed

Please help.

The unit tests are different than the tests directly in the notebook. There is a pretty obvious pattern to the differences between the “Expected” and “Actual” values. If you pass one test, but fail a different set of tests, then the first thing to consider is whether there is something “hard-coded” about your solution such that it matches the first set of tests. You can also read the unit test code to understand what is different about those tests. Click “File → Open” and then open the file w2_unittest.py.

Hi Paul,

Thank you for your response.
I have checked and don’t think anything is “hard-coded”
here are the variables.

{moderator edit - solution code removed}

Thank you for your help.

Sorry, but your logic is incorrect in several ways. E.g. why are you starting with row - 1? The loop is over row, right? That is not all that is wrong. There are several cases in which you are confusing the index of a row with the actual row.

My suggestion would be to start by taking one of the input test cases and actually work out the algorithm step by step with a pencil and paper. Then with that clear in your mind, then work through what your code would do in the same case. Once you have clear what is supposed to be happening, then that needs to inform how you write the code.

1 Like

Thank you Paul, will get onto it.