W4-1_E7 : Variable db gives error

Hello,

Context: Week 4 (Part 1) Exercise 7.

Possible Issue: In spite of trying multiple options for parameter ‘db’, errors continue to exist.
Please guide what exactly is going wrong.

Options Tried:
# db = (1/m)*dZ # FAIL
# db = (1/m)*np.sum(dZ,axis=1, keepdims= True) #FAIL
# db = (1/m)*np.sum(dZ,axis=1, keepdims= False) #FAIL
# db = (1/m)*np.sum(dZ,axis=0, keepdims= True) #FAIL
db = (1/m)*np.sum(dZ,axis=0, keepdims= False)

Error:

db: [ 0.70219802 -0.79066637 0.66968699 -0.97357906]
Error: Wrong shape for variable 2.
Error: Wrong output for variable 2.
1 Tests passed
2 Tests failed


AssertionError Traceback (most recent call last)
in
6 print("db: " + str(t_db))
7
----> 8 linear_backward_test(linear_backward)

~/work/release/W4A1/public_tests.py in linear_backward_test(target)
385 ]
386
→ 387 multiple_test(test_cases, target)
388
389 def linear_activation_backward_test(target):

~/work/release/W4A1/test_utils.py in multiple_test(test_cases, target)
140 print(‘\033[92m’, success," Tests passed")
141 print(‘\033[91m’, len(test_cases) - success, " Tests failed")
→ 142 raise AssertionError(“Not all tests were passed for {}. Check your equations and avoid using global variables inside the function.”.format(target.name))
143

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

Sincerely,
A

Instead of trying multiple things, read the instructions again and use your intuition to find out which one is correct. Of the equations you shared, one of them is correct.

Thanks Saif for response.
I got you. But, the correct solution should have no error.

In my view, calculations for variable ‘db’ should be column-wise, thus axis=0.

For db = (1/m)*np.sum(dZ,axis=0, keepdims= False):
Error Message: Screen Shot 2023-11-16 at 11.03.17 PM.png (attached)

For db = (1/m)*np.sum(dZ,axis=0, keepdims= True):



Error Message: Screen Shot 2023-11-16 at 11.04.27 PM.png (attached)

I also looked int the equation, and not sure how to pursue it forward…

Sincerely,
A

Please check this instruction from the notebook:

For the next exercise, you will need to remember that:

  • b is a matrix(np.ndarray) with 1 column and n rows, i.e: b = [[1.0], [2.0]] (remember that b is a constant)
  • np.sum performs a sum over the elements of a ndarray
  • axis=1 or axis=0 specify if the sum is carried out by rows or by columns respectively
  • keepdims specifies if the original dimensions of the matrix must be kept.
  • Look at the following example to clarify:

Hello Saif,

I am not aware of any notebook shared during the certification.
It would be great if you may share any course book.

I am currently referring to weekly .pdf files only.

“Look at the following example to clarify:”

  • I guess you were intending to post some examples as well.

Sincerely,
A