Hello all. There’s something in Exercise 3 related to Python that I don’t understand… In the ‘conv_forward’ function, there is a line in the ‘c’ for loop that calls the function ‘conv_single_step’, which was coded in the previous exercise. Here is the line:

Z[i, h, w, c] = conv_single_step(a_slice_prev, weights, biases)

But ‘conv_single_step’ returns Z, which is a scalar value. How are [i, h, w, c] assigned value by a function call that returns a single, scalar value? I was able to finish the HW based on reading the assertion hints, but I really want to understand this. Thanks in advance!

The scalar is just the value that the Z matrix contains at the intersection point (i, h, w, c) in a four-dimensional hyperplane.

Thank you for your response, cmarquay. But it’s still unclear to me.

Z[i, h, w, c] = conv_single_step(a_slice_prev, weights, biases)

If I print(Z), it prints a (2, 3, 4, 8) np.array.

If I change the line to ‘foo = conv_single_step(a_slice_prev, weights, biases)’ and print foo, then it prints the scalar return value from the function (which is what I would expect).

It’s a gap in my python knowledge, but I still don’t understand how the function returns any values to Z[i, h, w, c]. How/Where does the return value change Z[i, h, w, c]?

Can anyone explain it like they’re talking to a fifth grader?

Ah… I get it now. Each scalar return value is being written to the Z np.array. The specific location is defined by the looped values of [i, h, w, c]. Not sure why this took so long to understand…

Thanks for your help, Christian!

1 Like