Hi, I’m a bit stuck on the second exercise of C1W2 (back substitution). I’ve put quite a few print statements into my code to try to debug this.
The method is new to me, and I’m particularly confused by the lines in the exercise’s function that read as below - I’ve put in bold what I have replaced None with:
/code snippet removed/
All tests are failing. The output from the first test is below:
Wrong output for test case check_null_matrix.
Expected: [5 6 7]
Got: [-6 6 7]
I can share the output of the print / debug statements I have put in, for the first pass through the loops, if useful. Looking at the error trace, the code returns:
a value in the last position that matches the solution,
a value in index position -2 inconsistently matches the test value,
a value in my solution position is -3 consistently incorrect.
the line that originally read value = row_to_reduce[None] is particularly confusing for me, as when I had this line in this format, row_to_reduce contained an integer (index value), which couldn’t itself be indexed, so the code as-is caused an error. I have gone about this by changing the line to use the index and apply this to the Matrix, but, should I instead re-visit how row_to_reduce is being derived, if that should be iterable / indexable?
Any pointers or suggestions on where I may be going wrong or how to progress through this would be much appreciated as I’ve been stuck on this for a couple of days / keen to get my head around it so I can move on. Thanks.
please check the below thread if it helps understand your issue.
Also a heads-up, as it is your first post, you are not suppose to post any codes correct or incorrect, share link to assignment notebook on public post thread. it is against community guidelines.
thanks, and apologies for including the snippet (now removed) - I’ve read the linked post, but that one seems to be referring to exercise 1, when my problem is with exercise 2?
You substitution row codes under the for row loop is incorrect. You mentioned row-1, it should be rather M[row, :]
then for code line, Get the index of the first non-zero element in the substitution row. Remember it is stating to get the index in the substitution row and not the index of substitution row. You were suppose to use row instead of substitution_row.
Perform the back substitution step using the formula row_to_reduce → row_to_reduce - value * substitution_row
This code line instruction clearly mentions to use row_to_reduce -value * substitution_row, but instead you used M[substitution_row, :] which is incorrect.
Thanks so much for your help, really appreciate you sparing the time to look through it and help me out. Wasn’t aware of the file naming convention either, so appreciate the heads up.
You can understand on how to use this discourse community by going through FAQ section.
Also another pointer, when you come across any error, use the search option, many times learners have already come across similar error which might also help you in debugging but make sure not comment on older threads rather always create a new topic for your issue. You can share any link to those similar older threads if you find while you create a post.