Code seems to work fine but can't pass 1/2 tests

For implementing the L1 function:

def L1(yhat, y):
“”"
Arguments:
yhat – vector of size m (predicted labels)
y – vector of size m (true labels)

``````Returns:
loss -- the value of the L1 loss function defined above
"""

loss = (np.sum(abs(y - yhat))) / y.shape[0]

return loss
``````

The error:
yhat = np.array([.9, 0.2, 0.1, .4, .9])
y = np.array([1, 0, 0, 1, 1])
print("L1 = " + str(L1(yhat, y)))

L1_test(L1)

L1 = 0.22000000000000003 Error: Wrong output 1 Tests passed 1 Tests failed

AssertionError Traceback (most recent call last)
in
3 print("L1 = " + str(L1(yhat, y)))
4
----> 5 L1_test(L1)

~/work/release/W2A1/public_tests.py in L1_test(target)
216 ]
217
→ 218 test(test_cases, target)
219
220 def L2_test(target):

~/work/release/W2A1/test_utils.py in test(test_cases, target)
24 print(‘\033[92m’, success," Tests passed")
25 print(‘\033[91m’, len(test_cases) - success, " Tests failed")
—> 26 raise AssertionError(“Not all tests were passed for {}. Check your equations and avoid using global variables inside the function.”.format(target.name))

AssertionError: Not all tests were passed for L1. Check your equations and avoid using global variables inside the function.

Please check the formulas for the L1 and L2 loss functions that they are defining here. They are defined as the sum, not the mean, of the individual loss values on each sample.

You’re right that later we will switch to using loss functions that are the mean of the losses on the individual samples, but not in this particular exercise. This is really more just about numpy.