Hello @vishu_bandari,
Itâs important to analyze the error traceback because it can give us a lot of information in code debugging. It traced from the function that we call on the jupyter notebook, down to the call of the last function that really triggers the error, and in your case, we need to focus on here:
The error happened in the propagate
function which is our exercise 5. The arrow tells us which line had triggered the error, and combining with the error message that there were unaligned shapes, we can deduce that the problem is at np.dot
.
A dot product dots two matrices together, and the rule for a valid dot product is, as told in the error message, the first matrixâs last shape value be equal to the second matrixâs first shape value. Your Y
had a shape of (1, 7)
, whereas your np.log(A)
had a shape of (1, 4)
, and that violated the rule.
Now the problem is, despite you had passed many tests, probably including the ones for propagate
, was your implementation for it indeed wrong?
If you also read the DocString for propagate
:
"""
Implement the cost function and its gradient for the propagation explained above
Arguments:
w -- weights, a numpy array of size (num_px * num_px * 3, 1)
b -- bias, a scalar
X -- data of size (num_px * num_px * 3, number of examples)
Y -- true "label" vector (containing 0 if non-cat, 1 if cat) of size (1, number of examples)
Return:
cost -- negative log-likelihood cost for logistic regression
dw -- gradient of the loss with respect to w, thus same shape as w
db -- gradient of the loss with respect to b, thus same shape as b
Tips:
- Write your code step by step for the propagation. np.log(), np.dot()
"""
Y
is supposed to have a shape of (1, # samples)
which is consistent with the shape revealed in the error message. A
isnât listed in the DocString but since we know how we calculated A
, we can judge that the shape revealed in the error for A
is reasonable.
With the shapes of Y
and A
reasonable but the rule for a valid dot product was violated, I believe thatâs where you need to make some corrections for.
Above is how I would analyze your bug report, and I hope this can be an example for your future debugging work!
Cheers,
Raymond