Hello,
I completed the row_echelon_form and ran (print)row_echelon_form(A,B), and got what I expected. However when running “w2_unittest.test_row_echelon_form(row_echelon_form)” I got an error message saying it expected on array and got another. The “received” array looked nothing like the array I got when I ran the print statement. It also said I passed 3 tests and failed 1.

I’ve tried saving my notebook under a different name, deleting the original, and get the latest version.

When a unit test fails it means your code implementation is wrong, there maybe various reasons for that including hardcoding variables! Go back and check your implementation for this case!

Not familiar with this course but what are you doing here? M[starting_row:,column])?

If you want to choose only one element of the M matrix then this need be M[starting_row,column]), but I dont know what the goal here so maybe another mentor that has done this course can help better!

That part is actually provided in the assignment. It’s supposed to build an array of just the column, starting with row = starting_row.

Here’s the rest of the function:

Get the column array starting from the specified row

column_array = M[starting_row:,column]
for i, val in enumerate(column_array):
# Iterate over every value in the column array.
# To check for non-zero values, you must always use np.isclose instead of doing "val == 0".
if not np.isclose(val, 0, atol = 1e-5):
# If one non zero value is found, then adjust the index to match the correct index in the matrix and return it.
index = i + starting_row
return index
# If no non-zero value is found below it, return -1.
return -1

But the point is that the inputs to that function are the results of your code in row_echelon_form, right? So it’s that logic that must be wrong, not the “helper” function they gave you. Perfectly correct functions can fail if you pass them incorrect data.

Please show us the full output trace you are getting with the failure.

The other thing to note is that the unit tests may cover more cases than the visible tests you see in the notebook. It’s always a true statement that just passing one test is not enough to guarantee your code is fully correct. You can examine the unit test logic to understand what is being tested by clicking “File → Open” and then opening w2_unittest.py and having a look. If you can figure out which of the tests is actually failing, one debugging approach would be to “play out” that test case with pencil and paper first and then compare that to what your code is doing.

I was wrong about those values being correct. I forgot array index starts at zero,

I’ve changed the arrays to the ones in unittest, so I have a better idea of what’s going on, but I’m going to have to set this aside for the moment and come back to it later today or tomorrow.

I just meant all the printed output you get when you run the test that is failing. E.g. if I intentionally create a bug in my row_echelon_form function and run it, here’s what I get: