# C1\_w3 assignment question 3

**URL:** <https://community.deeplearning.ai/t/c1-w3-assignment-question-3/282812>\
**Category:** Linear Algebra for Machine Learning and Data Sc...\
**Tags:** week-module-3\
**Created:** [March 1, 2023, 12:52am UTC](https://community.deeplearning.ai/t/c1-w3-assignment-question-3/282812 "2023-03-01T00:52:10Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Janiromi](https://avatars.discourse-cdn.com/v4/letter/j/54ee81/32.png) [@Janiromi](https://community.deeplearning.ai/u/Janiromi)\
**Post date:** [March 1, 2023, 12:52am UTC](https://community.deeplearning.ai/t/c1-w3-assignment-question-3/282812/1 "2023-03-01T00:52:10Z")

</div>

Hey so, I answered question 3 and got to the following part:

# Note:

# Actual values are not checked here in the unit tests (due to random initialization).

w3\_unittest.test\_initialize\_parameters(initialize\_parameters)

So does this mean that I have to change my results in order to match the expected output?  
Because afterwards I get the following:

AssertionError Traceback (most recent call last)  
 in   
1 # Note:  
2 # Actual values are not checked here in the unit tests (due to random initialization).  
----\> 3 w3\_unittest.test\_initialize\_parameters(initialize\_parameters)

~/work/w3\_unittest.py in test\_initialize\_parameters(target\_initialize\_parameters)  
185  
186 for test\_case in test\_cases:  
 → 187 result = target\_initialize\_parameters(test\_case[“input”][“n\_x”], test\_case[“input”][“n\_y”])  
188  
189 try:

in initialize\_parameters(n\_x, n\_y)  
14 ### END CODE HERE ###  
15  
—\> 16 assert (W.shape == (1, 1))  
17 assert (b.shape == (1, 1))  
18

AssertionError:

So I don’t know if I am right or if I am wrong. Thanks \<3

 ![image](https://global.discourse-cdn.com/dlai/original/3X/0/5/054f216e2e5eb0b845cbce601aa1960a6a5a1008.png)

---

<div class="post-metadata">

**Author:** ![paulinpaloalto](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/paulinpaloalto/32/187_2.png) [@paulinpaloalto](https://community.deeplearning.ai/u/paulinpaloalto)\
**Post date:** [March 1, 2023, 2:24am UTC](https://community.deeplearning.ai/t/c1-w3-assignment-question-3/282812/2 "2023-03-01T02:24:24Z")

</div>

Hi, Janina. I’m not a mentor for M4ML, but notice what that assertion is doing: it is checking the _shape_ of your W value, not the actual numeric values. It should be a 1 x 1 numpy array, but apparently it isn’t. That is what that failure message is telling you. So what shape is it? You can add a print statement to your function to find out:

`print(f"W.shape = {W.shape}")`

What do you see when you do that? Then the question is why did it not turn out to be 1 x 1? There must be something wrong with the way you specified the dimensions to the random function.

---

<div class="post-metadata">

**Author:** ![Lidia\_Krinova](https://avatars.discourse-cdn.com/v4/letter/l/b9bd4f/32.png) [@Lidia\_Krinova](https://community.deeplearning.ai/u/Lidia_Krinova)\
**Post date:** [March 2, 2023, 4:15am UTC](https://community.deeplearning.ai/t/c1-w3-assignment-question-3/282812/3 "2023-03-02T04:15:47Z")

</div>

![Снимок экрана 2023-03-02 в 7.11.48](https://global.discourse-cdn.com/dlai/original/3X/8/5/8509f213cfaa27223145edc69cebd2226e6382c7.png)  
I also have an error in this exercise. Can you please give a hint what i did wrong  
Thank you

---

<div class="post-metadata">

**Author:** ![paulinpaloalto](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/paulinpaloalto/32/187_2.png) [@paulinpaloalto](https://community.deeplearning.ai/u/paulinpaloalto)\
**Post date:** [March 2, 2023, 3:35pm UTC](https://community.deeplearning.ai/t/c1-w3-assignment-question-3/282812/4 "2023-03-02T15:35:24Z")

</div>

Just like the previous question on this thread, that assertion is telling you that the shape of the W value that your code produced is not correct. The _shape_ of a numpy vector or matrix or array is the number of dimensions it has and the sizes of those various dimensions. So the first question is “what shape is it actually?” I showed how to figure that out in my previous reply. Then the next question is “why did it turn out incorrectly?” Once you see what the incorrect shape is, that should be a pretty good clue as to where your mistake is. Most likely you are passing the wrong arguments to the “random” function that generates that values.

---

<div class="post-metadata">

**Author:** ![Abdulhaq\_Salako\_Teej](https://avatars.discourse-cdn.com/v4/letter/a/ad7895/32.png) [@Abdulhaq\_Salako\_Teej](https://community.deeplearning.ai/u/Abdulhaq_Salako_Teej)\
**Post date:** [March 2, 2023, 10:38pm UTC](https://community.deeplearning.ai/t/c1-w3-assignment-question-3/282812/5 "2023-03-02T22:38:03Z")

</div>

![image](https://global.discourse-cdn.com/dlai/original/3X/8/f/8f1d3bb660c76c76aae6aec850719d6019ae59fd.png)  
 ![image](https://global.discourse-cdn.com/dlai/original/3X/e/1/e163ed841f1cb0f15d28923249c4fea6277171df.png)  
I don’t know why I’m getting errors even though the W.shape is (1,1). Can anyone Elaborate

---

<div class="post-metadata">

**Author:** ![Maryia\_Znak](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/maryia_znak/32/40965_2.png) [@Maryia\_Znak](https://community.deeplearning.ai/u/Maryia_Znak)\
**Post date:** [March 2, 2023, 10:49pm UTC](https://community.deeplearning.ai/t/c1-w3-assignment-question-3/282812/6 "2023-03-02T22:49:49Z")

</div>

Pay attention to the order of args in np.random.randn() method (check the order in the comment and then in your implementation :))

---

<div class="post-metadata">

**Author:** ![Abdulhaq\_Salako\_Teej](https://avatars.discourse-cdn.com/v4/letter/a/ad7895/32.png) [@Abdulhaq\_Salako\_Teej](https://community.deeplearning.ai/u/Abdulhaq_Salako_Teej)\
**Post date:** [March 3, 2023, 5:08pm UTC](https://community.deeplearning.ai/t/c1-w3-assignment-question-3/282812/7 "2023-03-03T17:08:40Z")

</div>

I see that. Thanks for the tip 😃

---

<div class="post-metadata">

**Author:** ![gccadori](https://avatars.discourse-cdn.com/v4/letter/g/97f17d/32.png) [@gccadori](https://community.deeplearning.ai/u/gccadori)\
**Post date:** [March 22, 2023, 12:29pm UTC](https://community.deeplearning.ai/t/c1-w3-assignment-question-3/282812/8 "2023-03-22T12:29:32Z")

</div>

Hello folks,

@paulinpaloalto: I have checked my matrix size and it is correct. W is a 1x1 matrix.

@Maryia_Znak: I have also checked the use of arguments in the function but still I am getting the assertion error messagemwhen running the test unit code block.

Please find below how the function is written.

_{moderator edit - solution code removed}_

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

---

<div class="post-metadata">

**Author:** ![paulinpaloalto](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/paulinpaloalto/32/187_2.png) [@paulinpaloalto](https://community.deeplearning.ai/u/paulinpaloalto)\
**Post date:** [March 22, 2023, 2:50pm UTC](https://community.deeplearning.ai/t/c1-w3-assignment-question-3/282812/9 "2023-03-22T14:50:37Z")

</div>

Please read the error trace more carefully. In your case it is not the W value that has the incorrect shape: it is the b value. The assertion about the shape of W did not fail and the little arrow on the exception trace points at the assertion about the shape of b, right? Once you realize that, it’s also easy to find the bug. 🤓

---

<div class="post-metadata">

**Author:** ![gccadori](https://avatars.discourse-cdn.com/v4/letter/g/97f17d/32.png) [@gccadori](https://community.deeplearning.ai/u/gccadori)\
**Post date:** [March 23, 2023, 6:28pm UTC](https://community.deeplearning.ai/t/c1-w3-assignment-question-3/282812/10 "2023-03-23T18:28:48Z")

</div>

Thanks, Paul. I managed to make it work earlier yesterday but still don’t fully comprehend why “1” works and why “n\_x” (which equals to 1) would not work.

---

<div class="post-metadata">

**Author:** ![paulinpaloalto](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/paulinpaloalto/32/187_2.png) [@paulinpaloalto](https://community.deeplearning.ai/u/paulinpaloalto)\
**Post date:** [March 24, 2023, 12:42am UTC](https://community.deeplearning.ai/t/c1-w3-assignment-question-3/282812/11 "2023-03-24T00:42:44Z")

</div>

The point is that we are writing general code here, which should work for any input values. Just because `n_x` happens to be 1 in the one test case that you can see does not mean it will always be one, right? There are multiple test cases in the unit test for this function and some of them must use a different value of `n_x`. So you are making an invalid assumption: an assumption that does not generalize.

---

<div class="post-metadata">

**Author:** ![gccadori](https://avatars.discourse-cdn.com/v4/letter/g/97f17d/32.png) [@gccadori](https://community.deeplearning.ai/u/gccadori)\
**Post date:** [March 24, 2023, 2:12am UTC](https://community.deeplearning.ai/t/c1-w3-assignment-question-3/282812/12 "2023-03-24T02:12:21Z")

</div>

Paul - that answers my question. Thank you for the clarification. Appreciate the support 🤝🤝

---

<div class="post-metadata">

**Author:** ![alison\_barbi](https://avatars.discourse-cdn.com/v4/letter/a/74df32/32.png) [@alison\_barbi](https://community.deeplearning.ai/u/alison_barbi)\
**Post date:** [July 9, 2023, 2:21am UTC](https://community.deeplearning.ai/t/c1-w3-assignment-question-3/282812/13 "2023-07-09T02:21:28Z")

</div>

Maryia\_Znak  
I had the same problem.  
I read your comment.  
I fixed it.  
Thank you so much!  
Alison

---

<div class="post-metadata">

**Author:** ![alison\_barbi](https://avatars.discourse-cdn.com/v4/letter/a/74df32/32.png) [@alison\_barbi](https://community.deeplearning.ai/u/alison_barbi)\
**Post date:** [July 9, 2023, 2:23am UTC](https://community.deeplearning.ai/t/c1-w3-assignment-question-3/282812/14 "2023-07-09T02:23:55Z")

</div>

This comment helped fix my code.  
Thank you.  
I am taking the google crash course in Python next on your recommendation.  
Thank you.  
Alison  
M4ML C1\_W3
