def propagate(w, b, X, Y):

m = X.shape[1]

A = (np.dot(w.T,X))+b

error here —> cost = np.dot((-1/(m)), (np.sum( np.dot(Y, np.log(A)) + np.dot((1 - Y) , np.log(1-A)) ) ) )

dw = np.dot((1/(X.shape(1))) , (np.dot(X, (A-Y).T)) )

db = np.dot((1/(X.shape(1))), (np.sum(A-Y)))

cost = np.squeeze(np.array(cost))

grads = {“dw”: dw,

“db”: db}

```
return grads, cost
```

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

I could not spot my mistake, can anyone help please? Am I on the right track or is my work completely nonsense?

Thanks in advance.

Hi @Efe_Baydar welcome to Discouse and I hope you are enjoying the course.

You are not completely off track, don’t worry. Have a look at the hints above the instruction. It indicates how you have to calculate A, which should use the sigmoid function. So let’s first fix that, and then check the rest.

1 Like

def propagate(w, b, X, Y):

m = X.shape[1]

A = sigmoid ( np.dot(w.T,X))+b )

cost = np.dot( (- 1/(m) ), ( np.sum( np.dot(Y, np.log(A) ) + np.dot( (1 - Y ) , np.log( 1-A ) ) ) ) )

dw = np.dot((1/(X.shape(1))) , (np.dot(X, (A-Y).T)) )

db = np.dot((1/(X.shape(1))), (np.sum(A-Y)))

cost = np.squeeze(np.array(cost))

grads = {“dw”: dw,

“db”: db}

return grads, cost

Thank you, yes I missed the sigmoid function, although I still couldn’t spot the problem.

You also need to understand how “dot products” work: notice that you are dotting a 1 x m vector with a 1 x m vector. That does not make sense and that is exactly what the error message is telling you. So how can you fix that? What you want is to dot 1 x m with m x 1 and that will give you a 1 x 1 (scalar) result, right? So how can you convert that second argument from 1 x m to m x 1?