C1_W2_Assignment RowAdd not exchanging intended row

Hi Everybody, I have a question about the C1-W2 Assignment.

Here is my AddRows function, which passes all the tests:

def AddRows(M, row_num_1, row_num_2, row_num_1_multiple):
M_new = M.copy()
# multiply row_num_1 by row_num_1_multiple and add it to the row_num_2,
# exchanging row_num_2 of the matrix M_new with the result
M_new[row_num_2] = (row_num_1_multiple * M_new[row_num_1]) + M_new[row_num_2]
return M_new

However, when I use this function to to row operations in Exercise 4, it keeps resulting in row_num_1 getting added to when I only want to to add it to another row. In other words, the AddRows function results in adding the result to both rows in the parameter, not only to the intended “exchange” row. I used exactly the same syntax as last week’s lab where it works as intended, but without making this function work properly everything else fails.

Does anybody have any insight as to how to preserve the original row values of row_num_1 while adding them to another row as in Gaussian elimination?


Hi @Rod_Bennett

Sorry for the late reply. Your function seems correct. Can you share your notebook privately? The error might be on how you called AddRows.

No worries man, I finished this class back in May haha.

That’s great! It’s how you used it in the code right? Because your function is correct.

I don’t remember exactly, but it was something very minor