# DLS2 week3: programming assignment eror linear\_function

**URL:** <https://community.deeplearning.ai/t/dls2-week3-programming-assignment-eror-linear-function/688647>\
**Category:** Improving Deep Neural Networks: Hyperparameter tun\
**Tags:** week-module-3, coursera-platform\
**Created:** [September 6, 2024, 11:07am UTC](https://community.deeplearning.ai/t/dls2-week3-programming-assignment-eror-linear-function/688647 "2024-09-06T11:07:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![benebo](https://avatars.discourse-cdn.com/v4/letter/b/e495f1/32.png) [@benebo](https://community.deeplearning.ai/u/benebo)\
**Post date:** [September 6, 2024, 11:07am UTC](https://community.deeplearning.ai/t/dls2-week3-programming-assignment-eror-linear-function/688647/1 "2024-09-06T11:07:54Z")

</div>

Hi everyone:)

the very first functionto be defined: linear\_function won’t return the expected value:

my code:  
{mentor edit: code removed}

the result:  
[[0.90226924]  
[0.7439407]  
[1.0854228]  
[0.8581807]]

the expected result:  
[[-2.15657382]  
[2.95891446]  
[-1.08926781]  
[-0.84538042]]

note that I did try leaving the typedefinition away, as well as including the name tag for the tf.constants, but the values obviously do not change.

could it be that the nb.random.seed(1) content changed?

thanks for any help!

Bene

---

<div class="post-metadata">

**Author:** ![nadtriana](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/nadtriana/32/167698_2.png) [@nadtriana](https://community.deeplearning.ai/u/nadtriana)\
**Post date:** [September 6, 2024, 11:45am UTC](https://community.deeplearning.ai/t/dls2-week3-programming-assignment-eror-linear-function/688647/2 "2024-09-06T11:45:20Z")

</div>

The error you encountered in **Exercise 1 - linear\_function** is likely related to how the random numbers are generated. Based on your code in the `linear_function`, you used `np.random.rand()` instead of `np.random.randn()`. The `rand()` function generates random numbers between 0 and 1, while `randn()` generates random numbers from a normal distribution (centered at 0 with a standard deviation of 1).

---

<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 6, 2024, 7:35pm UTC](https://community.deeplearning.ai/t/dls2-week3-programming-assignment-eror-linear-function/688647/3 "2024-09-06T19:35:07Z")

</div>

Just a reminder, please avoid posting your code in the future, that’s not allowed by the Code of Conduct.

---

<div class="post-metadata">

**Author:** ![benebo](https://avatars.discourse-cdn.com/v4/letter/b/e495f1/32.png) [@benebo](https://community.deeplearning.ai/u/benebo)\
**Post date:** [September 7, 2024, 11:37am UTC](https://community.deeplearning.ai/t/dls2-week3-programming-assignment-eror-linear-function/688647/4 "2024-09-07T11:37:50Z")

</div>

oh damn, thanks @nadtriana  
alright sorry, won’t do it again @TMosh
