Course 4 Week 1 assignment - weights for conv_forward function

The weights are giving me a lot of trouble in the conv_forward function of Exercise 3. I have my weight matrix assigned to W[everything, everything, everything, index by channel) because I assume I have to slice the weights for the specific channel, but I keep getting an error “IndexError: too many indices for array”, and the error arrow is pointing at the line where I calculated W. I think the main problem is that I can’t visualise this last step. I thought I was extracting (using index c) the weights of the current channel, out of the n_C total?

Please post the full exception :slight_smile:

Here is the full exception: I also printed out the shapes of my calculated a_prev_pad, W and b and they are: a_prev_pad shape = (7, 9, 4), W shape=(3, 3, 4), b shape=(1,1,1)

you are overwriting the variable W with a slice of W with one dimension less. Rename both W and b to something like weightsand bias as recommended in the comments:

                    # weights = None
                    # biases = None
                    # Z[i, h, w, c] = None

Please also remove your solution if my help works out for you :slight_smile:

1 Like

Thanks - I just realised too that a change of variable name was all that was required as you can’t write a numpy array of one dimension to overwrite a numpy array of a different dimension. Thanks again! Removed the solution.

1 Like