# Question on when initializing the parameters

**URL:** <https://community.deeplearning.ai/t/question-on-when-initializing-the-parameters/470694>\
**Category:** Calculus for Machine Learning and Data Science\
**Tags:** week-module-3\
**Created:** [October 16, 2023, 8:46am UTC](https://community.deeplearning.ai/t/question-on-when-initializing-the-parameters/470694 "2023-10-16T08:46:27Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mohammad\_Omar\_Adde](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/mohammad_omar_adde/32/67669_2.png) [@Mohammad\_Omar\_Adde](https://community.deeplearning.ai/u/Mohammad_Omar_Adde)\
**Post date:** [October 16, 2023, 8:46am UTC](https://community.deeplearning.ai/t/question-on-when-initializing-the-parameters/470694/1 "2023-10-16T08:46:27Z")

</div>

W = np.random.randn(n\_y, n\_x) \* 0.01  
b = np.zeros((n\_y, 1))

why n\_y comes before n\_x and also n\_y, 1 is there a reason.

---

<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:** [October 16, 2023, 9:51am UTC](https://community.deeplearning.ai/t/question-on-when-initializing-the-parameters/470694/2 "2023-10-16T09:51:50Z")

</div>

Hi @Mohammad_Omar_Adde ,

The generation of weight matrix, W, reflects the network structure. So what we have here is that n\_x is the number of units in the input layer, X; n\_y is the number of units in the output layer. The network diagram should indicate the arrangement.

n\_y comes before n\_x because the network is moving in the direction from input to output. When initialise b, the bias vector, np.zeros() is called with the shape of the array as argument, where the 1 means it is a column vector.

---

<div class="post-metadata">

**Author:** ![Mohammad\_Omar\_Adde](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/mohammad_omar_adde/32/67669_2.png) [@Mohammad\_Omar\_Adde](https://community.deeplearning.ai/u/Mohammad_Omar_Adde)\
**Post date:** [October 16, 2023, 9:58am UTC](https://community.deeplearning.ai/t/question-on-when-initializing-the-parameters/470694/3 "2023-10-16T09:58:14Z")

</div>

thanks for the clarification. 🙏

---

<div class="post-metadata">

**Author:** ![Mohammad\_Omar\_Adde](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/mohammad_omar_adde/32/67669_2.png) [@Mohammad\_Omar\_Adde](https://community.deeplearning.ai/u/Mohammad_Omar_Adde)\
**Post date:** [October 16, 2023, 10:05am UTC](https://community.deeplearning.ai/t/question-on-when-initializing-the-parameters/470694/4 "2023-10-16T10:05:00Z")

</div>

Hi @Kic  
sorry, why 0.01 is there a reason, because i thing the instructor don’t mention during the lecture.

---

<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:** [October 16, 2023, 4:10pm UTC](https://community.deeplearning.ai/t/question-on-when-initializing-the-parameters/470694/5 "2023-10-16T16:10:12Z")

</div>

Hi @Mohammad_Omar_Adde

Multiplying the output from random.randn() by 0.01 would scale down the values. It doesn’t change the essence of data.

---

<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:** [October 16, 2023, 5:19pm UTC](https://community.deeplearning.ai/t/question-on-when-initializing-the-parameters/470694/6 "2023-10-16T17:19:27Z")

</div>

There is some theoretical basis for selecting the range of the random initial values. It’s complicated, as it depends on the size of the NN, the number of layers, the numbers of units, etc. It’s an area of some research.

In practice you just try values between 0 and +1, or -1 and +1, and see how it goes. You may need to adjust the multiplier depending on your specific model.

---

<div class="post-metadata">

**Author:** ![Mohammad\_Omar\_Adde](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/mohammad_omar_adde/32/67669_2.png) [@Mohammad\_Omar\_Adde](https://community.deeplearning.ai/u/Mohammad_Omar_Adde)\
**Post date:** [October 16, 2023, 5:38pm UTC](https://community.deeplearning.ai/t/question-on-when-initializing-the-parameters/470694/7 "2023-10-16T17:38:15Z")

</div>

i really appreciate you, as mentors for your clear answers,

i tried using local machine and i have the data set there but if i try to run the code some where in the middle the two answers are not similar, the instructor’s answer and mine, even if take similar seed as the instructor, and the course is calculus week 3 notebook one linear regression

---

<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:** [October 16, 2023, 6:21pm UTC](https://community.deeplearning.ai/t/question-on-when-initializing-the-parameters/470694/8 "2023-10-16T18:21:44Z")

</div>

Please post a screen capture that image that shows the results you mentioned.
