Help: my code is correct but the grader gives me 66%

For the 4-th week of course 4, my codes of the face recolonization projects are correct and pass all tests but the grader report the following error and give me grade 66%.

Code Cell UNQ_C2: Unexpected error (TypeError(“ufunc ‘isfinite’ not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ‘‘safe’’”)) occurred during function check. We expected function verify to return verify test 1 failed. Please check that this function is defined properly.

It appears that your code passes the tests in the notebook, but does not pass one of the tests used by the grader.

The grader’s tests are different than the notebook’s tests.

This implies there is an error in your code. The error involves the use of the isfinite() function.

Does your code use the isfinite() function? I’m not aware of any need to use this function, but perhaps is it invoked by the lower code layers.

The isfinite function is used by the testing logic.

As Tom says, there is probably something wrong with your code. I find that I can provoke exactly that error on the verify function if I use np.linalg.norm to compute the distance, but specify the axis. This has the effect of converting the answer to a 1D numpy array instead of a scalar.

Try adding a print statement like this right before your return statement in verify:

print(f"type(dist) = {type(dist)}")

What does that show in your case? What you want to see is this:

type(dist) <class 'numpy.float32'>

But if you see this, you’re in trouble:

type(dist) <class 'numpy.ndarray'>

Thanks a lot, folks! I fix this problem by correcting my code so that the dist is a float not an array any more.