# Week 4 In 93 def initialize\_parameters(n\_x, n\_h, n\_y)

**URL:** <https://community.deeplearning.ai/t/week-4-in-93-def-initialize-parameters-n-x-n-h-n-y/882914>\
**Category:** AI Discussions\
**Tags:** introductions\
**Created:** [November 7, 2025, 8:55am UTC](https://community.deeplearning.ai/t/week-4-in-93-def-initialize-parameters-n-x-n-h-n-y/882914 "2025-11-07T08:55:51Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![vcychan](https://avatars.discourse-cdn.com/v4/letter/v/6bbea6/32.png) [@vcychan](https://community.deeplearning.ai/u/vcychan)\
**Post date:** [November 7, 2025, 8:55am UTC](https://community.deeplearning.ai/t/week-4-in-93-def-initialize-parameters-n-x-n-h-n-y/882914/1 "2025-11-07T08:55:51Z")

</div>

I fail in In 93 def initialize\_parameters(n\_x, n\_h, n\_y)

def initialize\_parameters(n\_x, n\_h, n\_y):  
“”"  
Argument:  
n\_x – size of the input layer  
n\_h – size of the hidden layer  
n\_y – size of the output layer

```auto
Returns:
parameters -- 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)
"""
np.random.seed(1)

#(≈ 4 lines of code)
# W1 = ...
# b1 = ...
# W2 = ...
# b2 = ...
# YOUR CODE STARTS HERE
W1 = np.random.rand(n_h, n_x)*0.01
#print("Mark 1 W1="+str(W1))
b1 = np.zeros([n_h, 1])
W2 = np.random.rand(n_y, n_h)*0.01
#print("Mark 2 W2="+str(W2))
b2 = np.zeros([n_y, 1])
# YOUR CODE ENDS HERE
parameters = {"W1": W1,
              "b1": b1,
              "W2": W2,
              "b2": b2}

return parameters    

The output is this.

Test Case 1:

W1 = [[4.17022005e-03 7.20324493e-03 1.14374817e-06]
 [3.02332573e-03 1.46755891e-03 9.23385948e-04]]
b1 = [[0.]
 [0.]]
W2 = [[0.0018626 0.00345561]]
b2 = [[0.]]
Error: Wrong output for variable W1.
Error: Wrong output for variable W2.
 1 Tests passed
 1 Tests failed

```

---

<div class="post-metadata">

**Author:** ![Kic](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/kic/32/76339_2.png) [@Kic](https://community.deeplearning.ai/u/Kic)\
**Post date:** [November 7, 2025, 12:53pm UTC](https://community.deeplearning.ai/t/week-4-in-93-def-initialize-parameters-n-x-n-h-n-y/882914/2 "2025-11-07T12:53:00Z")

</div>

Hi @vcychan ,

To generate the weights, you need to use **np.random.randn** as specified in the instructions.

Please post your query in the forum specific for your course for speedy response.

---

<div class="post-metadata">

**Author:** ![TMosh](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/tmosh/32/9321_2.png) [@TMosh](https://community.deeplearning.ai/u/TMosh)\
**Post date:** [November 7, 2025, 6:00pm UTC](https://community.deeplearning.ai/t/week-4-in-93-def-initialize-parameters-n-x-n-h-n-y/882914/3 "2025-11-07T18:00:15Z")

</div>

What course are you attending? You did not mention this, nor did you post your message in the forum for any course.

---

<div class="post-metadata">

**Author:** ![vcychan](https://avatars.discourse-cdn.com/v4/letter/v/6bbea6/32.png) [@vcychan](https://community.deeplearning.ai/u/vcychan)\
**Post date:** [November 8, 2025, 5:10am UTC](https://community.deeplearning.ai/t/week-4-in-93-def-initialize-parameters-n-x-n-h-n-y/882914/4 "2025-11-08T05:10:35Z")

</div>

> [@vcychan](#):
>
> `I used this.`
> 
> `W1 = np.random.rand(n_h, n_x)*0.01`

W2 = np.random.rand(n\_y, n\_h)\*0.01

The error were shown.

Error: Wrong output for variable W1.  
Error: Wrong output for variable W2.  
1 Tests passed  
1 Tests failed

I studying the Deep Learning course. Can you give me the forum URL?

---

<div class="post-metadata">

**Author:** ![TMosh](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/tmosh/32/9321_2.png) [@TMosh](https://community.deeplearning.ai/u/TMosh)\
**Post date:** [November 8, 2025, 8:14am UTC](https://community.deeplearning.ai/t/week-4-in-93-def-initialize-parameters-n-x-n-h-n-y/882914/5 "2025-11-08T08:14:56Z")

</div>

You can find it in the “Course Q&A” topic, in the left-side menu.

---

<div class="post-metadata">

**Author:** ![Kic](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/kic/32/76339_2.png) [@Kic](https://community.deeplearning.ai/u/Kic)\
**Post date:** [November 8, 2025, 12:44pm UTC](https://community.deeplearning.ai/t/week-4-in-93-def-initialize-parameters-n-x-n-h-n-y/882914/6 "2025-11-08T12:44:58Z")

</div>

Hi @vcychan ,

The instructions for this exercise specified to use np.random. **randn** , which is different from the function you used. It is important to read the instructions for correct implementation. Otherwise, your code would not give the output as expected. This is what happened in your case.
