C1_W3_Final_Lab_Error_Unsupported Format String

Hi - i am getting an error, which traces back to the section of the code that is un-editable. This is for the final lab for Course 1. Specifically, the cell ‘def compute_cost’ accepts my code additions but then the cell directly below that, produces this error “TypeError: unsupported format string passed to numpy.ndarray._format_”. Thank you for your help.

Hello, @CSAWS,

This happens when cost is a numpy array which it should not be. The docstring of compute_cost specifically listed the returning value to be a scalar. You may print(type(total_cost)) to check the current type, but make it scalar will clear this error.

Cheers,
Raymond

Hi and thank you. the cell that has the code that you are recommending to revise is locked as this is a graded lab and i only can edit certain cells within the lab. where this error is occurring is in a cell that is locked for editing. any suggestions? thanks again.

As pointed out by Raymond, your compute_cost function has problem. It should return single number(scalar?) but it is returning np array(as show in the error).

Check the hints..

1 Like

Raymond, thank you for the information. As a follow-up, the lab I am working on is a graded lab and there is no way (as far as I know) for me to change the code to what you referencing as it is locked by Coursera. I tried using the logic you referenced in my graded coding section but the error message continues to occur. Any further guidance is appreciated.

Thx,

Chris

The cells that are locked are just tests of the code you added to some other function. You cannot (and do not need to) modify the test cells.

The tests tell you if the functions you modified are working correctly.

If a test fails, the fix is to repair your code. Not to wish to modify the test cell.

got if figured out…thank you!

1 Like

Hello @CSAWS, I am sorry for getting back to you late but I am glad you have it figured out with @aaparmar’s help.

As Tom has explained and also what you are going to see in all subsequent labs, only the cells that contain a graded function are editable and the testing cells are locked. If you see an error in a testing cell, we need to look back at the associated graded function.

Those cells are locked to avoid any unwanted changes that may cause a submission to fail, so we can focus entirely on getting the graded functions right.

Cheers,
Raymond