# Size of W in \[9\] in C2\_W1\_Lab02\_CoffeeRoasting\_TF?

**URL:** <https://community.deeplearning.ai/t/size-of-w-in-9-in-c2-w1-lab02-coffeeroasting-tf/183634>\
**Category:** Advanced Learning Algorithms\
**Tags:** week-module-1\
**Created:** [August 12, 2022, 5:00pm UTC](https://community.deeplearning.ai/t/size-of-w-in-9-in-c2-w1-lab02-coffeeroasting-tf/183634 "2022-08-12T17:00:05Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Robert\_Ascan](https://avatars.discourse-cdn.com/v4/letter/r/bc8723/32.png) [@Robert\_Ascan](https://community.deeplearning.ai/u/Robert_Ascan)\
**Post date:** [August 12, 2022, 5:00pm UTC](https://community.deeplearning.ai/t/size-of-w-in-9-in-c2-w1-lab02-coffeeroasting-tf/183634/1 "2022-08-12T17:00:06Z")

</div>

in [9]:

- In the first layer with 3 units, we expect W to have a size of (2,3) … .

Do I understand it correctly that W is a 2-D matrix with the size (2, 3) - 2 rows x 3 columns and it is because we have 3 units/neurons in the first layer each of which gets “fed” with a training data sample which have 2 features (temp and duration)? If correct, then why it is not of shape (3, 2)?

- In the second layer with 1 unit, we expect W to have a size of (3,1) … .

Is the W in the second layer a 2-D matrix with the size ( **3** , 1) and this is because it is an output of layer 1 (input to layer 2) that has **3** units? Why do we then have 1 column (not 2, for 2 features)?

Thanks ahead!

---

<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:** [August 12, 2022, 5:14pm UTC](https://community.deeplearning.ai/t/size-of-w-in-9-in-c2-w1-lab02-coffeeroasting-tf/183634/2 "2022-08-12T17:14:30Z")

</div>

Each weight matrix connects two adjacent layers.

- So the first weight matrix has the size of the number of input features and the number of hidden layer units.

- The second weight matrix has the size of the number of hidden layer units and the number of outputs.

---

<div class="post-metadata">

**Author:** ![Robert\_Ascan](https://avatars.discourse-cdn.com/v4/letter/r/bc8723/32.png) [@Robert\_Ascan](https://community.deeplearning.ai/u/Robert_Ascan)\
**Post date:** [August 12, 2022, 5:43pm UTC](https://community.deeplearning.ai/t/size-of-w-in-9-in-c2-w1-lab02-coffeeroasting-tf/183634/4 "2022-08-12T17:43:31Z")

</div>

Thanks, TMosh! One more question: why is the first weight matrix of the shape (2, 3) but not (3, 2), to keep it consistent with the shape of the second weight matrix)?

---

<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:** [August 12, 2022, 6:08pm UTC](https://community.deeplearning.ai/t/size-of-w-in-9-in-c2-w1-lab02-coffeeroasting-tf/183634/5 "2022-08-12T18:08:58Z")

</div>

If I recall correctly, the shape is typically (outputs x inputs). I haven’t checked the details on this assignment though.

---

<div class="post-metadata">

**Author:** ![Martin\_Thomas\_Mathew](https://avatars.discourse-cdn.com/v4/letter/m/dfb087/32.png) [@Martin\_Thomas\_Mathew](https://community.deeplearning.ai/u/Martin_Thomas_Mathew)\
**Post date:** [October 19, 2022, 3:55pm UTC](https://community.deeplearning.ai/t/size-of-w-in-9-in-c2-w1-lab02-coffeeroasting-tf/183634/6 "2022-10-19T15:55:26Z")

</div>

Thank you for raising this question. I too am confused about it.  
TMosh, I still am confused despite reading your responses.

These 2 responses seem contradictory:

1. [Size of W in [9] in C2\_W1\_Lab02\_CoffeeRoasting\_TF? - #2 by TMosh](https://community.deeplearning.ai/t/size-of-w-in-9-in-c2-w1-lab02-coffeeroasting-tf/183634/2)
2. [Size of W in [9] in C2\_W1\_Lab02\_CoffeeRoasting\_TF? - #5 by TMosh](https://community.deeplearning.ai/t/size-of-w-in-9-in-c2-w1-lab02-coffeeroasting-tf/183634/5)

The first reply matches with how it is in the lab.

If I apply the 2nd comment to the neural network in this label,

> shape is typically (outputs x inputs).

Layer 1 shape should be (3,2) because as output you get 3 activation values and input is of 2 features.  
Layer 2 shape also should be (1,3) because you get 1 activation output value using 3 inputs

I see it intuitively as W matrix for Layer 1 as (3,2) and W matrix for Layer 2 as (1,3).

Please advise. Would really too sort this confusion out.  
Thank you 🙏

---

<div class="post-metadata">

**Author:** ![Martin\_Thomas\_Mathew](https://avatars.discourse-cdn.com/v4/letter/m/dfb087/32.png) [@Martin\_Thomas\_Mathew](https://community.deeplearning.ai/u/Martin_Thomas_Mathew)\
**Post date:** [October 19, 2022, 7:41pm UTC](https://community.deeplearning.ai/t/size-of-w-in-9-in-c2-w1-lab02-coffeeroasting-tf/183634/7 "2022-10-19T19:41:07Z")

</div>

It’s clear now. Prof. Andrew explains the parameter W shape in Section: Neutral Network implementation in Python. Video: General implementation of forward propogation.  
TMosh, thank you.
