Function layer_sizes() requires different constants at different places

In week 3 coding assignmnet, in order to pass the first test associated with just the function layer_sizes(), you must hardcode n_x=5, n_h=4
, n_y=2. However, to get the function nn_model() to work, the sizes hard coded in must be n_x=2, n_h=4
, n_y=1. Therefore, I can only make one of these functions work at a time, and the grader is giving me 0/100. I think the template code is erroneous in that it I must assign the layer sizes 5,4,2, when this is clearly not the network we’re using. Could someone either fix the template or tell me what I may have done wrong?

Thanks.

The point is that the test case for layer_sizes is just testing it as a general purpose function. There is no reason why it should not be able to handle completely arbitrary values. It is a mistake to hard-code thing just as a general matter, but they do ask you to do that for n_h in this particular case. The other sizes will be determined by the shapes of the objects passed in when you call the various layers of functions here. The whole point of creating functions is that they are reusable, right? Did you read the “hint” that they give you in the instructions?

1 Like