Help with Week 1 Programming assignment: initialize Z

I am working on the conv_forward function where we are supposed to initialize the output volume Z with 0s.

I tried initializing Z with np.zeros and using the dimensions of (m, n_H, n_W, n_C). Yielded an Assertion Error of “Wrong shape. Don’t hard code the pad and stride values in the function”

I am just confused about where the dimensions come from for Z.

I’m sorry if this has been answered already. I am finding Discourse not very easy to search, especially since most of the threads consist of “I had this problem, no wait I fixed it”.

Thanks for any help you can give me. I’ll go back to my code now and hopefully have an epiphany.

np.zeros() requires that you pass it the dimensions as a tuple.
So in python syntax, you have to enclose the dimensions inside nested pairs of ((…)).

So this works:
Z = np.zeros((m, n_H, n_W, n_C))

1 Like

The best way to search the Forum for answers is to include the course, week, and assignment (i.e. “C4 W1 A1”), or to search by the function name.

1 Like

Thank you for your help. It turns out that I was doing the initialize Z with np.zeros correctly, but when calculating n_H and n_W I had forgotten to divide by stride.