DLS Course2 Week1 Regularization Exercise 3

{moderator edit - solution code removed}

Hello,

I think the shape of W1 in test is (2, n) in exercise 3 but (20, n) in exercise 4 ( which is consitent with the notes). Thus, I use shape instead of a specific number. I am not sure if I get it right so please check the notes. :slight_smile:

Best,
Haotian

1 Like

Hello @Ruan_Haotian,
w1 is a weight matrix of shape (layers_dims[1], layers_dims[0]). layers_dims[1] is the dimension of hidden layer 1 which you you normally choose when design your own neural network. However, it was set 20 for this specific problem. And layers_dims[0] is the size of the input. It is 2 in this case.

1 Like

Yes, it is never a good idea to hard-code any dimensions, unless you literally don’t have a choice. So using the shapes of the inputs is definitely the way to go. But note that it’s really the shape of A1 that you want to duplicate in that case, right? So you could have written that code more simply by using *A1.shape as the argument to rand.

It is a good point that it’s a mistake for the “docstring” to call out specific dimensions like that. I think that bug was filed a long time ago, but apparently hasn’t been fixed yet.

2 Likes