C1 W2 A2 propagate

This is the error i’m getting.


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 = sigmoid(np.dot(w.T,X)+b)
—> 34 cost = (-1/m) * (np.sum(np.dot(Y,(np.log(A))))+(np.dot((1-Y),(np.log(1-A)))))
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)

It is fine to use np.dot to compute the cost, but the problem is Y and A are both 1 x m vectors, so you can’t just dot them “as is”: the dimensions don’t work. You need to understand how matrix multiplication works as a prerequisite here. Here’s another recent thread about this.

1 Like

Yes i got it. I did not think it through. Thanks for the help.

Glad to hear that you solved it. For future reference, the error message was pretty clear in pointing to what the problem was.