Week 4 - exercise 4

Hi,
I am getting the following error. any advise what I am doing wrong?

ipython-input-25-ae7fefbf1b01> in linear_activation_forward(A_prev, W, b, activation)
23 # YOUR CODE STARTS HERE
24
—> 25 Z, linear_cache = np.dot(W, A_prev)+ b
26
27 A, activation_cache= sigmoid(Z)

ValueError: not enough values to unpack (expected 2, got 1)

You are saying that the right hand side of that assignment statement produces two output values, but it clearly doesn’t. That is why that error is thrown.

Now the question is how to fix it. Rather than manually implementing the linear activation at that point in the code, you have already built a function to do that, right? Notice also that it returns two values. Hmmmmm. :thinking:

1 Like

Hi @paulinpaloalto ,

I am currently have the same issue. I have input
Z,linear_cache = sigmoid(np.dot(W,A_prev)+b),
A, activation_cache = sigmoid(Z)

The answer is the same as I gave earlier on this thread: why manually implement things at this level? You already have built linear_forward for performing the operation of the first line that you show, right?

Hi @paulinpaloalto

Thank you for replying to my question. I’ve since changed it to
Z, linear_cache = linear_forward(W, A_prev, b)
A, activation_cache = sigmoid(Z)

But now faced with the issue of the shapes not being aligned…

What is the actual exception trace that you get in that case? Note that this may mean that you are passing incorrect arguments down to this function.

Hi @paulinpaloalto

in linear_activation_forward(A_prev, W, b, activation)
22 # A, activation_cache = …
23 # YOUR CODE STARTS HERE
—> 24 Z, linear_cache = linear_forward(W, A_prev, b)
25 A, activation_cache = activation(Z)
26 # YOUR CODE ENDS HERE

in linear_forward(A, W, b)
18 # Z = …
19 # YOUR CODE STARTS HERE
—> 20 Z = np.dot(W, A) + b
21
22 # YOUR CODE ENDS HERE

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

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

That’s the error…

You are calling linear_forward incorrectly: you have reversed the first two arguments.