Hi,

I’ve tested my code and wasn’t able to find why my test is failing. I’d really appreciate it if you could help me pass this test.

Hi,

I’ve tested my code and wasn’t able to find why my test is failing. I’d really appreciate it if you could help me pass this test.

Notice that all your W1 and W2 output values are positive and between 0 and 1. If you look at the expected values, they are both positive and negative. The most likely cause is that you used the wrong random function. Probably you used `np.random.rand`

. They basically wrote the code for you in the instructions and that’s not the function that they used. Please have another look at the sample code in the instructions.

Thanks for your prompt reply @paulinpaloalto !

The instructions are misleading. Reverse engineering based on what the test was implemented on is a waste of time. I can genereate a random matrix between -1 and 1 in infinite ways.

You are spot on, I’ve used np.random.rand. The function definition doesn’t say much but their shape.

“”"

Argument:

n_x – size of the input layer

n_h – size of the hidden layer

n_y – size of the output layer

```
Returns:
params -- python dictionary containing your parameters:
W1 -- weight matrix of shape (n_h, n_x)
b1 -- bias vector of shape (n_h, 1)
W2 -- weight matrix of shape (n_y, n_h)
b2 -- bias vector of shape (n_y, 1)
```

“”"

The instructions are not misleading. Please read them again. They are very specific in terms of showing you what the function call should look like. All you need to do is figure out how to express the correct shapes. They told you to use `np.random.randn`

, but that is not what you did. “`rand`

” is not the same as “`randn`

”.

1 Like

@paulinpaloalto you saved my day. Thank you so much!

“randn” are not the same as “rand”. Noted!

I am right now feeling the pain of why this naming convention was used for such a vastly used library, numpy.

rand is for uniform distribution and randn is used for normal distribution.

what about naming them rand_uniform and rand_normal?

I am taking a break to heal from this

The instructions were too correct haha!

Cheers!

1 Like

Yes, they could have chosen better (more distinct) names for the functions. But the overall point is that programming is a game of details. Well, it’s both big conceptual ideas and excruciating details, which is what makes it challenging. The difference between “:” and “;” can ruin your whole afternoon.

The other big lesson here is that “saving time” by not reading carefully is almost never a net savings of time.

1 Like