Hi,

I am getting Assertion error.

I have initialized b as 0.0

Hi, @_mahi. The `AssertionError`

is telling you that `db`

is of the wrong type, which suggests to me that you need to first check your expression for `db = ...`

in the `propagate()`

function. Are you using `np.sum`

in your expression or the native Python function `sum`

? Do not use the latter.

Dear All, anything wrong in the following code

# cost = …

```
# YOUR CODE STARTS HERE
A = np.dot((w.T),X) + b;
cost = np.sum((np.multiply(Y,A)) + (np.multiply((1-Y),(np.log(1-A)))))/m
# YOUR CODE ENDS HERE
# BACKWARD PROPAGATION (TO FIND GRAD)
#(≈ 2 lines of code)
# dw = ...
# db = ...
# YOUR CODE STARTS HERE
dz = A - Y
dw = np.dot(X,(dz.T))
dw /= m
db = np.sum(dz)/m
# YOUR CODE ENDS HERE
cost = np.squeeze(np.array(cost))
grads = {"dw": dw,
"db": db}
return grads, cost
```

after running this code, i am getting the following error

AssertionError Traceback (most recent call last)

in

14 print ("cost = " + str(cost))

15

—> 16 propagate_test(propagate)

~/work/release/W2A2/public_tests.py in propagate_test(target)

39 assert type(grads[‘dw’]) == np.ndarray, f"Wrong type for grads[‘dw’]. {type(grads[‘dw’])} != np.ndarray"

40 assert grads[‘dw’].shape == w.shape, f"Wrong shape for grads[‘dw’]. {grads[‘dw’].shape} != {w.shape}"

—> 41 assert np.allclose(grads[‘dw’], expected_dw), f"Wrong values for grads[‘dw’]. {grads[‘dw’]} != {expected_dw}"

42 assert np.allclose(grads[‘db’], expected_db), f"Wrong values for grads[‘db’]. {grads[‘db’]} != {expected_db}"

43 assert np.allclose(cost, expected_cost), f"Wrong values for cost. {cost} != {expected_cost}"

AssertionError: Wrong values for grads[‘dw’]. [[ 5.55 ]

[14.985]

[ 5.985]] != [[-0.03909333]

[ 0.12501464]

[-0.99960809]]

Expected output

dw = [[ 0.25071532]

[-0.06604096]]

db = -0.1250040450043965

cost = 0.15900537707692405

please someone correct my code, thank you

Using np.sum worked!

Thanks!

Great! I was a longtime Matlab user and so had a number of issues thinking about what I going on under the hood of NumPy via Python. Now, I love the flexibility!