Course 1: Neural Network and Deep Learning

In Week 2, Python Basics with numpy assignment why does ques 8 why does loss=np.sum(np.abs(y-yhat),keepdims=True) not work?

Because the type of the output is not what the test case is expecting. Why do you need the “keepdims = True” there? That has the effect of making the output a 1 x 1 numpy array, instead of a scalar. You can demonstrate this by adding the following code:

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

What do you see when you do that? Now try it again without the keepdims and see what happens.