# Week 2 code assignment error

**URL:** <https://community.deeplearning.ai/t/week-2-code-assignment-error/186076>\
**Category:** Supervised ML: Regression and Classification\
**Tags:** week-module-2\
**Created:** [August 15, 2022, 8:06pm UTC](https://community.deeplearning.ai/t/week-2-code-assignment-error/186076 "2022-08-15T20:06:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Elise\_Poniman](https://avatars.discourse-cdn.com/v4/letter/e/c5a1d2/32.png) [@Elise\_Poniman](https://community.deeplearning.ai/u/Elise_Poniman)\
**Post date:** [August 15, 2022, 8:06pm UTC](https://community.deeplearning.ai/t/week-2-code-assignment-error/186076/1 "2022-08-15T20:06:59Z")

</div>

While doing the code assignment for the compute cost part, I tried to run the code and this came out. Can anyone help me with this? Thanks in advance

 ![MLss1](https://global.discourse-cdn.com/dlai/original/3X/8/9/89bc1ec0e2906308ef3ca120902e50c19cd9d8d0.png)

---

<div class="post-metadata">

**Author:** ![rmwkwok](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/rmwkwok/32/126977_2.png) [@rmwkwok](https://community.deeplearning.ai/u/rmwkwok)\
**Post date:** [August 15, 2022, 10:51pm UTC](https://community.deeplearning.ai/t/week-2-code-assignment-error/186076/2 "2022-08-15T22:51:58Z")

</div>

Hi @Elise_Poniman,

The error indicates that the `cost` variable that your `compute_cost` function produces is an array, which should have been a `float` type instead. You may start debugging from here.

 ![Screenshot from 2022-08-16 06-51-27](https://global.discourse-cdn.com/dlai/original/3X/9/9/99790aed3ac6e48acac0de7501d10e65357a340a.png)

Raymond

---

<div class="post-metadata">

**Author:** ![stephanho](https://avatars.discourse-cdn.com/v4/letter/s/e56c9b/32.png) [@stephanho](https://community.deeplearning.ai/u/stephanho)\
**Post date:** [August 15, 2022, 10:53pm UTC](https://community.deeplearning.ai/t/week-2-code-assignment-error/186076/3 "2022-08-15T22:53:36Z")

</div>

The variable `cost` that you calculated outputs an array, but it should be a scalar.  
The string formatting part (the `.3f`) in the print statement requires a scalar. That’s why it yields the `TypeError`. Please check the output of your function `compute_cost`.

---

<div class="post-metadata">

**Author:** ![rmwkwok](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/rmwkwok/32/126977_2.png) [@rmwkwok](https://community.deeplearning.ai/u/rmwkwok)\
**Post date:** [August 20, 2022, 2:09am UTC](https://community.deeplearning.ai/t/week-2-code-assignment-error/186076/4 "2022-08-20T02:09:16Z")

</div>

Hi @Elise_Poniman , I am closing this thread, please open a new one if you have any follow-up.

Raymond

---

<div class="post-metadata">

**Author:** ![rmwkwok](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/rmwkwok/32/126977_2.png) [@rmwkwok](https://community.deeplearning.ai/u/rmwkwok)\
**Post date:** [August 20, 2022, 2:09am UTC](https://community.deeplearning.ai/t/week-2-code-assignment-error/186076/5 "2022-08-20T02:09:19Z")

</div>

Closed on August 20, 2022, 2:09am UTC


