Ex 4 of assignment 1 (week 2)= initialise and propagate

the errors are with the ‘initialise parameters’ and the ‘propagate’ functions.

  1. i initialise b as b=float(0). This works , but the system also says, “data type not understood”
  2. in ‘propagate’, the system says, "invalid syntax’, for this code:
    dw=(np.dot(X,np.transpose(A-Y)))/m
    or
    dw=(1/m)*(np.dot(X,np.transpose(A-Y)))
    with the caret marker below ‘dw’.
    I have checked the previous statement, to calculate J, and it is ok.

You may want to read through the whole block of code again. The error(s) might not necessarily caused by those lines you pointed to. Or you can try running one line at a time until you see an error pops up.

That probably means that you have a missing close parenthesis on the previous non-comment line before the dw line.

Dear Sir,
The issue i am facing is this:
When ‘propagate’ is run, there is a statement: “assert grads[“db”]==np.float64”, which the code fails. Because db is ‘float’, not ‘float64’.
here it is:
assert type(grads[“dw”]) == np.ndarray
assert grads[“dw”].shape == (2, 1)
assert type(grads[“db”]) == np.float64

I have checked with type(db) statements, tried to ‘cast’, etc, but I could not convert db, which is an array, to np.float64, and the error remains.
my code for db is: db=(1/m)*sum(A-Y) and I have checked that ‘A’ is correct and ‘Y’ is as given. Kindly help. (I have completed week 3, but week 2 is stuck!)

Try using np.sum instead of sum in the computation of db. The quantity A - Y is a numpy array, so you need numpy functions to operate on it.