C1_W3Assignment... Completely Lost

Hi everyone. I was doing pretty well with this course, but I appear to have taken a wrong turn somewhere, completely hit a wall and now I think I need some help.

I passed the first exercise, but I don’t think it’s actually correct as everything I’ve been trying from then on doesn’t seem to be right.

Plus, despite me getting the first one right, the grader states all of them are wrong, and as there is not much information provided, I can’t see where the problems are (the reason given is the same for every exercise ‘There was a problem compiling the code from your notebook. Details:
operands could not be broadcast together with shapes (1,30) (2,)’).

Let me know what information I can provide to get the ball rolling and I’ll do so. If anyone can assist, I would very much appreciate it.

1 Like

Hi @Martin_Pollard ,

There are a few steps before the ex4 and ex5, it could be any of these steps including ex4 and ex5 are coded incorrectly. The broadcast problem arises from the dot product calculation in forward_propagation(). So you need to go back and check from ex2 onwards.

1 Like

Thanks @Kic. Turns out ex1 was actually incorrect (or… inaccurate) after all so I managed to fix it. I think I can where the specific problem may be occurring in ex2, but I still don’t know how to fix it.

I don’t understand what the hints are getting at:

'Use shapes of X and Y to find n_x and n_y:

  • the size of the input layer n_x equals to the size of the input vectors placed in the columns of the array X,
  • the outpus for each of the data point will be saved in the columns of the the array Y.’

Would you be able to please direct me to the video/part of the course that goes into this in more detail? I would much prefer to solve it that way than just ask for the answer or rely on hints.

2 Likes

Hi @Martin_Pollard ,

You can revisit the video lectures for week3 to better understand the concepts presented. Leaning new concepts takes time and going over the lectures is a good way to re-enforce our learning.

The Hint is trying to help you visualize the network configuration in terms of the input array X, and output array Y.

n_x is the size of the input layer, that is the number of features that we are interested in for this network. Each data example used for this network will have those features. In this lab, the input array X is arranged to have the features as row and the examples as column. So if there are 3 features for this network, then each example, ie. each column, will be a vector of 3 features, and the size of the input layer will be 3, the number of features.

Here is a diagram of a simple network, I hope it would help.

1 Like

Thanks @Kic - your explanation of the input layer is bringing this closer to a solution.

Unfortunately, the videos didn’t really help me further. As they are based on the underlying math rather than translating it into Python, I feel as though I completely missed something somewhere. I get the first half of ex2 correct, but then it only finds 1 rather than the expected values.

I can visualise the network more clearly now, and I think I understand how the shape of the matrix may relate to it, but evidently I have no idea how to express that in code and get the input layer. I did have a look at the codebase for numpy too, but either I missed what I was looking for or it’s more complicated than that.

Sorry but I will need some further assistance here please.

2 Likes

Hi @Martin_Pollard

The layer_sizes() function has two arguments:
X – input dataset of shape (input size, number of examples)
Y – labels of shape (output size, number of examples)

In 1.3, the dataset section, X and Y are created and reshaped to an array of 1 row, and 30 examples:

X= X.shape(1, 30)
Y= Y.shape(1, 30)

So, when X and Y passed to the layer_sizes() function, we can finding out how many elements are in the row of X:
n_x= np.size(X,0) here the 0 means row

equally, we can do the same for Y
n_y= np.size(Y,0)

If you want the number of elements in column, ie, the number of examples in Y
m= np.size(Y,1)

1 Like

That did it. Thanks for that Kic! You know, I had another look in the codebase I was referring to after your post and I couldn’t see np.size anywhere.

There were a few other elements to fix up in the other exercises and it took a while, but I’m happy to say that I have now managed to pass this assignment.

Honestly, I do think this assignment is actually too difficult (or maybe obscure?), but I very much appreciate your help.

On to week 4!

2 Likes

Hi @Martin_Pollard ,

Great to hear you have successfully finished the assignment. If you think the assignment could be better communicate (make clearer) to the learners, then, do post a comment to the course staff with your suggestions for improvement.

This was bit tricky. Was stuck here for long time, finally completed it.

Thank you @Martin_Pollard for raising this point and Thank @Kic for the explanation :slight_smile:

1 Like

Glad it helped you out!

1 Like

Hi I am also doing every exercise correctly but still it is giving an error

1 Like

Yes I too was stuck on the size issue for awhile…I think the example labs need to implement the np.size function more so we can better understand - just my 2 cents.

Thanks for the help…onward and upward!

2 Likes

Hi, sorry to bug you I am stuck on Exercise 5. - Initialize Paramaters.

The assignments tip is # Initialize parameters
### START CODE HERE ### (~ 1 line of code)

I have used 2

W =parameters[“W”]
b =parameters[“b”]

and am lost.

1 Like

I think you could try:

parameters = initialize_parameters(n_x, n_y)

1 Like