# C2 W3 Programming Assignment TensorFlow Introduction

**URL:** <https://dlai.staged-by-discourse.com/t/c2-w3-programming-assignment-tensorflow-introduction/496964>\
**Category:** Improving Deep Neural Networks: Hyperparameter tun\
**Tags:** coursera-platform\
**Created:** [November 17, 2023, 8:59am UTC](https://dlai.staged-by-discourse.com/t/c2-w3-programming-assignment-tensorflow-introduction/496964 "2023-11-17T08:59:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Surya\_Narayanan\_K](https://avatars.discourse-cdn.com/v4/letter/s/e95f7d/32.png) [@Surya\_Narayanan\_K](https://dlai.staged-by-discourse.com/u/Surya_Narayanan_K)\
**Post date:** [November 17, 2023, 8:59am UTC](https://dlai.staged-by-discourse.com/t/c2-w3-programming-assignment-tensorflow-introduction/496964/1 "2023-11-17T08:59:46Z")

</div>

Hello!

I have a problem with the computation of the cost in the function # GRADED FUNCTION: compute\_cost of the last Assignment of Improving Deep Neural Networks: Hyperparameter Tuning, Regularization and Optimization.

I was sure I had no mistake, while the expected cost is 0.810287 and my function does not pass the tests. Can you verify, please, that there are no mistakes in the verification part? Also, the explanation part according to which we have to implement the function is confusing. Can I have a discussion with the instructor to clarify? Thank you!

**ValueError: Shapes (6, 2) and (1, 6, 2) are incompatible**

MY CODE IS

```
YOUR CODE STARTS HERE

```

_{moderator edit - solution code removed}_

---

<div class="post-metadata">

**Author:** ![saifkhanengr](https://sea1.discourse-cdn.com/dlaistaging/user_avatar/dlai.staged-by-discourse.com/saifkhanengr/32/152858_2.png) [@saifkhanengr](https://dlai.staged-by-discourse.com/u/saifkhanengr)\
**Post date:** [November 17, 2023, 10:47am UTC](https://dlai.staged-by-discourse.com/t/c2-w3-programming-assignment-tensorflow-introduction/496964/2 "2023-11-17T10:47:09Z")

</div>

Please share your full error. Maybe reading [this](http://dlai.staged-by-discourse.com/t/week-3-exercise-6-compute-total-loss/306713/5) help.

---

<div class="post-metadata">

**Author:** ![paulinpaloalto](https://sea1.discourse-cdn.com/dlaistaging/user_avatar/dlai.staged-by-discourse.com/paulinpaloalto/32/187_2.png) [@paulinpaloalto](https://dlai.staged-by-discourse.com/u/paulinpaloalto)\
**Post date:** [November 17, 2023, 4:13pm UTC](https://dlai.staged-by-discourse.com/t/c2-w3-programming-assignment-tensorflow-introduction/496964/3 "2023-11-17T16:13:12Z")

</div>

There is no problem in the verification code that is given to you.

You have not specified the arguments to the loss function correctly, but that is not the reason for that particular error. Please check the definition of the loss function. There is something wrong with the shape of one of the `labels` or `logits` arguments. That must mean that you did the transpose incorrectly. There should be no “reshape” operation involved. They should both have shape (2, 6) by the time the loss function is called.

Also note that `new_y_train` is passed as the Y argument in the test case and that value was created by the output of your previous `one_hot_matrix` function, so the error may be there.

[Here’s another thread](http://dlai.staged-by-discourse.com/t/week-3-compute-total-loss-incorrect/291048/2) with a checklist of common errors on this function.

---

<div class="post-metadata">

**Author:** ![paulinpaloalto](https://sea1.discourse-cdn.com/dlaistaging/user_avatar/dlai.staged-by-discourse.com/paulinpaloalto/32/187_2.png) [@paulinpaloalto](https://dlai.staged-by-discourse.com/u/paulinpaloalto)\
**Post date:** [November 17, 2023, 4:57pm UTC](https://dlai.staged-by-discourse.com/t/c2-w3-programming-assignment-tensorflow-introduction/496964/4 "2023-11-17T16:57:46Z")

</div>

I added some print statements to my code to show the shapes right before the call to the loss function and here’s what I see:

```auto
logits.shape (2, 6)
labels.shape (2, 6)
vector_loss [0.25361034 0.5566767]
total_loss = 0.8102869987
tf.Tensor(0.810287, shape=(), dtype=float32)
All test passed

```

---

<div class="post-metadata">

**Author:** ![Surya\_Narayanan\_K](https://avatars.discourse-cdn.com/v4/letter/s/e95f7d/32.png) [@Surya\_Narayanan\_K](https://dlai.staged-by-discourse.com/u/Surya_Narayanan_K)\
**Post date:** [November 17, 2023, 5:28pm UTC](https://dlai.staged-by-discourse.com/t/c2-w3-programming-assignment-tensorflow-introduction/496964/5 "2023-11-17T17:28:18Z")

</div>

Thank you it worked really and I came to know that dimensions of the logits are the problem here.
