# week2_Exercise 5 - propagate

code:

A=1/1+np.exp(-(np.matmul(w.T,X))+b)
cost=-((np.dot(Y,np.log(A)))+(np.dot((1-Y),np.log(1-A))))/m

dw=np.matmul(X,((A-Y).T))
db=np.sum(A-Y )

output:

ValueError Traceback (most recent call last)
in
3 X = np.array([[1., -2., -1.], [3., 0.5, -3.2]])
4 Y = np.array([[1, 1, 0]])
----> 5 grads, cost = propagate(w, b, X, Y)
6
7 assert type(grads[“dw”]) == np.ndarray

in propagate(w, b, X, Y)
32 # YOUR CODE STARTS HERE
33 A=1/1+np.exp(-(np.matmul(w.T,X))+b)
—> 34 cost=-((np.dot(Y,np.log(A)))+(np.dot((1-Y),np.log(1-A))))/m
35
36 # YOUR CODE ENDS HERE

<array_function internals> in dot(*args, **kwargs)

ValueError: shapes (1,3) and (1,3) not aligned: 3 (dim 1) != 1 (dim 0)

In your `cost` calculation, you have to use transpose for one term, `Y` or `A`.

but in the given formula it is not there,please see my image

hi Saif ,

but in the cost equation ,there is not matrix transpose term.

Thank you very much for responding

If you choose to use dot product, then you have to transpose one term. There are other ways too for which you don’t need transpose, like using multiply and then sum…

what should be the output of cost function ,wheather it is nd.array or float value.