Week 2 Exercise 5 transpose question

So, my question is about why in the cost function I needed to transpose A and not Y

{moderator edit - solution code removed}

I got the tests right, but I still don’t get it.

I don’t think you need to transpose A for this to work. What happens when you try removing the transpose for A (ie. use A instead of A.T)?

If it doesn’t work for some reason, can you do print(A.shape) and print (Y.shape) and tell us what their shapes are?

Yeah, that’s what I was thinking, it does’t really makes sense.

My sigmoid func: return 1/(1+np.exp(-z))

error when I don’t transpose A:
shapes (1,3) and (1,3) not aligned: 3 (dim 1) != 1 (dim 0)

A and Y shape are equal, that’s why the error:
(1, 3) =A.shape
(1, 3) = y.shape

mathematically it makes sense, but I don’t get my error codewise

Are you sure that error comes from the code for cost?

That specific error is more likely coming from the code for dw/db down below, where you need to call matmul and transpose accordingly.

If you’re still having issues, can you send me your code through direct message? I can help you debug.

1 Like

Here’s a thread which explains the mechanics of the operations there.

2 Likes