Week 1 Assignment 1 exercise 3 problem with A_prev

Hello! For the part of the exercise where they ask " Select ith training example’s padded activation" in the for loop, what I did was: A_prev_pad = A_prev_pad[ i, : , : , : ] . However, im getting the error in the image below. I do not understand it. From what I understand after I do A_prev_pad = zero_pad(A_prev, pad) to add the padding, I still have a 4 dimensional array right? So I do not understand why I am getting an Index error.

I would really appreciate any help, thank you in advance.

1 Like

Hello @Pamela_Carolina_Diaz!

Your implementation is correct but you are making one mistake. It is given that:

a_prev_pad = None               # Select ith training example's padded activation    

Don’t need to change the left-hand side.

Best,
Saif.

You are right! that fixed the error. But know I am not getting the correct results and I don’t see where the mistake is. The parts that I think might be wrong are the followings, maybe you can tell me if im doing something wrong:

  • To calculate the vertical and horizontal indexes im doin g vert_start = hstride and vert_end = hstride + f (the same for horizontal but with “w” instead of “h”)
    -To acces the part of the matrix we will convolve with the filter im doing
    a_slice_prev = a_prev_pad[vert_start:vert_end, horiz_start:horiz_end, :] as the fourth dimension regarding the “m example” was already removed when selecting a training example in the first loop
  • Inside the loop over the number of channels, to access the values for W and b im doing:
    weights = W[:,:,:,c]
    biases = b[:,:,:,c]

I don’t see what im doing wrong. I hope you can help me. Thank you very much

It seems correct to me. Maybe you are making mistake somewhere else. Click my name and send me your code in a private message.

Best,
Saif.

Thank you for sending me your code.

I don’t know what is the difference between np.full() and np.zeros() but it is recommended to use the np.zeros() to initialize the Z. Try it and let us know if it solves your problem.

Best,
Saif.

But I am curious to know why np.full() with 0 failed to pass the test, despite having the same type, shape, and values as np.zeors. Maybe @paulinpaloalto could help us to learn about this.

I tried to use np.zeros, but it only takes 3 input arguments and the dimensions of the Z vector are 4 right? I uploaded the error I get when using np.zeros

Use two more barckets, like np.zeros((…)).

That solved the problem! I am so thankful to you!

I am glad it worked for you.

Best,
Saif.

As Saif pointed out, you were using the wrong syntax when calling np.zeros. If you get strange error messages about arguments in the future, the first step would be to read the documentation for the function you are calling. E.g, in this case just google “numpy zeros”. :nerd_face:

It turns out that the way you specify the shape to np.zeros is different than it is for np.random functions.

One more thing I just figure it out that Z = np.full((m,n_H,n_W,n_C), 0) failed the test despite giving all the zero values, because it produces an array of zeros (integers). But Z = np.full((m,n_H,n_W,n_C), 0.) passed the test because it produces, like np.zeros(), an array of float.

Thanks, Saif. This is the first time I had heard of np.full and it’s pretty interesting. Glad that you figured out the root cause of the problem was the datatype. So we all learned something from this! That’s the best case scenario. :nerd_face:

1 Like

It was the first time for me too. As you said, “deep water.”
Happy Learning!

1 Like

Hi, Mansur.

Welcome to DLS Course 4. The second assignment in Week 1 takes the knowledge that we learned about how Convolution and Pooling layers work in the first “Step by Step” assignment and then applies that to build a couple of actual models. But now we are moving to using the TensorFlow/Keras framework to build the models.

If you have questions, it will be better if you can ask something specific rather than just saying “Please explain assignment 2”. With that general a question, where do we start? :nerd_face:

If you would like a bit more background on how the Keras Sequential and Functional APIs work, here’s a good explanatory thread to start with. Please have a look at that and see if it sheds any light on how to proceed with this assignment. The other general suggestion is that the notebooks try to give pretty complete explanations, so it’s also a good idea just to read everything again from the start and see if it makes more sense the second time through. When you get to some specific point that is not clear, then you have a good question to pose here.

1 Like

Hello, Paul.
I honestly don’t comprehend the assignment; there are too many errors in the code.

Sorry, but what am I supposed to say based on that? If you have many errors, then where do you start? How about starting with the first one and working on that? What is the error trace that you are getting?

But before we start down that road, did you do the other things that I suggested: reading that thread I linked that explains in more detail how to use the Sequential and Functional APIs? And reading through the instructions in the notebook again? Were there any things in the instructions you had questions about?

Also please keep in mind that no-one else can just directly look at your code in your notebooks. So we can only help based on what you tell us here on the forums. Meaning that you really have not given us anything to go on besides “I have lots of errors”.

1 Like

Thank you for your prompt response; honestly, I am having difficulty completing the week two project; I tried multiple times but it appears that I did not understand the method. should i book a Zoom call in your spare time so that you can thoroughly explain the concept? Despite the fact that I returned to complete the first lab in week one to check my grasp of the topic.
thank you.

Hi, Mansur.

Please realize that the mentors are volunteers here: we do not get paid to do this. We are happy to answer questions in writing in the public forum, so that the information may benefit other current and future students, but we don’t provide the type of individualized video tutoring that you are requesting. At least I personally do not prefer to do that, but you may get lucky and someone else will see this thread and contact you and offer to help in that way.

You didn’t answer my question about whether you had read this thread that I linked earlier.

Is this your first class in the DLS series? Or did you previously take DLS Course 1 and Course 2?

If you have not been through the TensorFlow Introduction in Week 3 of DLS Course 2, that might explain why you are having problems here. But note that you really have not given us any details about which parts you are having trouble with.

How about trying to ask one specific and concrete question here in writing about something that is puzzling you and seeing how that goes?

Regards,
Paul

1 Like

HI,
I appreciate you always being available to answer my queries. I’ll go back to it as you advised. In fact, this is my first time participating in the DLS series. Actually, I’m referring to the linear regression practice lab from the Week 2 practice lab for supervised machine learning regression and classification. with the problem statement below

Problem Statement

Suppose you are the CEO of a restaurant franchise and are considering different cities for opening a new outlet.

  • You would like to expand your business to cities that may give your restaurant higher profits.
  • The chain already has restaurants in various cities and you have data for profits and populations from the cities.
  • You also have data on cities that are candidates for a new restaurant.
    • For these cities, you have the city population.

Can you use the data to help you identify which cities may potentially give your business higher profits?.

The first problem is trying to load the dataset.

load the dataset

x_train, y_train = load_data()
i tried to edit but like that particular place is not editable.because i have started from the beginning