# How is W shape (3,1) and not (1,3)?

**URL:** <https://community.deeplearning.ai/t/how-is-w-shape-3-1-and-not-1-3/446585>\
**Category:** Advanced Learning Algorithms\
**Tags:** week-module-1\
**Created:** [September 15, 2023, 10:43pm UTC](https://community.deeplearning.ai/t/how-is-w-shape-3-1-and-not-1-3/446585 "2023-09-15T22:43:12Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![manalchetouani](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/manalchetouani/32/99416_2.png) [@manalchetouani](https://community.deeplearning.ai/u/manalchetouani)\
**Post date:** [September 15, 2023, 10:43pm UTC](https://community.deeplearning.ai/t/how-is-w-shape-3-1-and-not-1-3/446585/1 "2023-09-15T22:43:12Z")

</div>

![image](https://global.discourse-cdn.com/dlai/original/3X/3/c/3c8f502a249c3c08683536af0c2de69c30f54c2a.png)

In this second lab of the Week1 it is specified that W shape is (3,1) as i know W shape relies on the number of parameters, in the second layer, a shape is (3,1) so W shape has to be (1,3) … please what do you think ?

---

<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:** [September 15, 2023, 11:21pm UTC](https://community.deeplearning.ai/t/how-is-w-shape-3-1-and-not-1-3/446585/2 "2023-09-15T23:21:44Z")

</div>

Here are the sizes:

 ![image](https://global.discourse-cdn.com/dlai/original/3X/b/2/b2d068a5fd7e7850df6177b7dbbae70398e002a7.png)

Why do you feel W2 should be (1,3)?

---

<div class="post-metadata">

**Author:** ![Indra\_Neel](https://avatars.discourse-cdn.com/v4/letter/i/3ab097/32.png) [@Indra\_Neel](https://community.deeplearning.ai/u/Indra_Neel)\
**Post date:** [September 16, 2023, 9:01am UTC](https://community.deeplearning.ai/t/how-is-w-shape-3-1-and-not-1-3/446585/3 "2023-09-16T09:01:02Z")

</div>

That is because TensorFlow computes the weights in a row order fashion.  
The weights for `Layer2` are arranged as

W\_2 = \begin{bmatrix} w\_1^{[2]} \\ w\_2^{[2]} \\ w\_3^{[2]} \end{bmatrix}

So this results in `W2.shape = (3,1)`  
For more info check the : Coffee Roasting with numpy implementation notebook

---

<div class="post-metadata">

**Author:** ![manalchetouani](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/manalchetouani/32/99416_2.png) [@manalchetouani](https://community.deeplearning.ai/u/manalchetouani)\
**Post date:** [September 20, 2023, 10:38am UTC](https://community.deeplearning.ai/t/how-is-w-shape-3-1-and-not-1-3/446585/4 "2023-09-20T10:38:52Z")

</div>

Hello TMosh,  
Thanks for your answer, so as you highlighted, W shape relies on number of features, well the number of feature from the activation layer 1 is 1 and the number of units is 1 so why it s not (1,1) ? I still dont get it … how come there are three features ?

---

<div class="post-metadata">

**Author:** ![manalchetouani](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/manalchetouani/32/99416_2.png) [@manalchetouani](https://community.deeplearning.ai/u/manalchetouani)\
**Post date:** [September 20, 2023, 10:42am UTC](https://community.deeplearning.ai/t/how-is-w-shape-3-1-and-not-1-3/446585/5 "2023-09-20T10:42:30Z")

</div>

Hello Indra Neel,  
Thank you for your answer, the way you put it together its more obvious for W to be of shape (3,1) i guess because the activation resulting from layer 1 has three rows. But as W is dependent to number of features, and as activation from layer 1 has only one feature, how come then W is three ? I hope my question is clear … thanks for advance

---

<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:** [September 20, 2023, 5:24pm UTC](https://community.deeplearning.ai/t/how-is-w-shape-3-1-and-not-1-3/446585/6 "2023-09-20T17:24:27Z")

</div>

The shape of W must match the number of features in X.

---

<div class="post-metadata">

**Author:** ![manalchetouani](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/manalchetouani/32/99416_2.png) [@manalchetouani](https://community.deeplearning.ai/u/manalchetouani)\
**Post date:** [September 20, 2023, 8:26pm UTC](https://community.deeplearning.ai/t/how-is-w-shape-3-1-and-not-1-3/446585/7 "2023-09-20T20:26:25Z")

</div>

I understand the W shape which is (2,3) in the first layer, but i cant get why its (3,1) for the second layer. Can you please help me ?

---

<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:** [September 20, 2023, 9:08pm UTC](https://community.deeplearning.ai/t/how-is-w-shape-3-1-and-not-1-3/446585/8 "2023-09-20T21:08:24Z")

</div>

The shape of W2 is based on the number of outputs and the number of hidden layer units.  
This is because it is what connects the hidden layer to the output layer.

---

<div class="post-metadata">

**Author:** ![manalchetouani](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/manalchetouani/32/99416_2.png) [@manalchetouani](https://community.deeplearning.ai/u/manalchetouani)\
**Post date:** [September 26, 2023, 12:54pm UTC](https://community.deeplearning.ai/t/how-is-w-shape-3-1-and-not-1-3/446585/9 "2023-09-26T12:54:39Z")

</div>

Hello Mr TMosh,

I apologise for my late reply, based on what is given in the course, W shape is based on the number of features ( which is in this case 1, please correct me if I am wrong, and the number of units, which is 1 so we re good on that.

So W being (3,1) I get why it is 1(one unit), but I don’t get the 3(are there really 3 features ? )

---

<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:** [September 26, 2023, 4:19pm UTC](https://community.deeplearning.ai/t/how-is-w-shape-3-1-and-not-1-3/446585/10 "2023-09-26T16:19:37Z")

</div>

> [@manalchetouani](#):
>
> which is in this case 1

The number of features depends on the dataset. There are multiple data sets used. They have different sizes.
