# C1\_W3\_Assignment # UNQ\_C1: error - wrong shape wrong output

**URL:** <https://community.deeplearning.ai/t/c1-w3-assignment-unq-c1-error-wrong-shape-wrong-output/144445>\
**Category:** AI for Medical Diagnosis\
**Tags:** week-module-3\
**Created:** [June 21, 2022, 7:58pm UTC](https://community.deeplearning.ai/t/c1-w3-assignment-unq-c1-error-wrong-shape-wrong-output/144445 "2022-06-21T19:58:15Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![edgarbc](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/edgarbc/32/15809_2.png) [@edgarbc](https://community.deeplearning.ai/u/edgarbc)\
**Post date:** [June 21, 2022, 7:58pm UTC](https://community.deeplearning.ai/t/c1-w3-assignment-unq-c1-error-wrong-shape-wrong-output/144445/1 "2022-06-21T19:58:15Z")

</div>

Hello,

I am getting the error:

( **Solution code removed, as sharing it publicly is against the honour code of this community** )

Thanks for any help/ideas!

---

<div class="post-metadata">

**Author:** ![Mubsi](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/mubsi/32/94983_2.png) [@Mubsi](https://community.deeplearning.ai/u/Mubsi)\
**Post date:** [June 22, 2022, 2:49pm UTC](https://community.deeplearning.ai/t/c1-w3-assignment-unq-c1-error-wrong-shape-wrong-output/144445/2 "2022-06-22T14:49:59Z")

</div>

Hi @edgarbc,

Can you share your lab ID with me ? In the assignment, when you click the top right “Help” button, a panel will open and your lab ID will be shown at the bottom.  
I shall take a look.

When you reply back, kindly tag me in the post so that I’m notified.

Thanks,  
Mubsi

---

<div class="post-metadata">

**Author:** ![edgarbc](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/edgarbc/32/15809_2.png) [@edgarbc](https://community.deeplearning.ai/u/edgarbc)\
**Post date:** [June 22, 2022, 3:02pm UTC](https://community.deeplearning.ai/t/c1-w3-assignment-unq-c1-error-wrong-shape-wrong-output/144445/3 "2022-06-22T15:02:43Z")

</div>

Hi @Mubsi ,

My lab ID is aqvowduz

Thanks for looking into this!

Best,  
Edgar

---

<div class="post-metadata">

**Author:** ![Mubsi](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/mubsi/32/94983_2.png) [@Mubsi](https://community.deeplearning.ai/u/Mubsi)\
**Post date:** [June 23, 2022, 2:13pm UTC](https://community.deeplearning.ai/t/c1-w3-assignment-unq-c1-error-wrong-shape-wrong-output/144445/4 "2022-06-23T14:13:15Z")

</div>

> [@edgarbc](#):
>
> aqvowduz

Hi @edgarbc,

In your `Ex 1`, when calculating the categorical values of `y` you were hardcoding the value of number of classes. As a rule, remember, _ **unless specifically asked to do so** _, never use hardcoded or global values in the graded functions.

You can take a look at your `Ex 1` for more information, it runs successfully now.

Best,  
Mubsi

---

<div class="post-metadata">

**Author:** ![edgarbc](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/edgarbc/32/15809_2.png) [@edgarbc](https://community.deeplearning.ai/u/edgarbc)\
**Post date:** [June 23, 2022, 3:07pm UTC](https://community.deeplearning.ai/t/c1-w3-assignment-unq-c1-error-wrong-shape-wrong-output/144445/5 "2022-06-23T15:07:52Z")

</div>

Oh I see. Thanks for your help @Mubsi !

---

<div class="post-metadata">

**Author:** ![cagschwarz](https://avatars.discourse-cdn.com/v4/letter/c/58956e/32.png) [@cagschwarz](https://community.deeplearning.ai/u/cagschwarz)\
**Post date:** [June 26, 2022, 2:19pm UTC](https://community.deeplearning.ai/t/c1-w3-assignment-unq-c1-error-wrong-shape-wrong-output/144445/6 "2022-06-26T14:19:04Z")

</div>

Hello @Mubsi,

I am also stuck with my UNQ\_C1 def\_get\_sub\_volume exercise - even after reading the forum and discourse posts - and was hoping you could help me as well.

The test cell is showing me:  
[…]  
Error: Wrong shape. for variable 1.  
Error: Wrong output. for variable in position 1.  
[…]  
1 Tests passed  
2 Tests failed

I presume the error is somewhere in the one-hot encoding but I can’t figure it out.

My labID is : dqfvmaab

Thanks for your help! It’s much appreciated 🙂

Christian

---

<div class="post-metadata">

**Author:** ![cagschwarz](https://avatars.discourse-cdn.com/v4/letter/c/58956e/32.png) [@cagschwarz](https://community.deeplearning.ai/u/cagschwarz)\
**Post date:** [June 27, 2022, 9:07am UTC](https://community.deeplearning.ai/t/c1-w3-assignment-unq-c1-error-wrong-shape-wrong-output/144445/7 "2022-06-27T09:07:08Z")

</div>

I think I could resolve the issue.

I hadn’t specified the num\_classes parameter when applying the keras.utils.to\_categorical method to y in order to one-hot-encode the label array y.

After defining the num\_classes parameter by setting it equal to the num\_classes variable that is input to the def\_get\_sub\_volume, the test cell showed the expected output without any error messages.

Hope this helps someone.

---

<div class="post-metadata">

**Author:** ![Mubsi](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/mubsi/32/94983_2.png) [@Mubsi](https://community.deeplearning.ai/u/Mubsi)\
**Post date:** [June 28, 2022, 7:18pm UTC](https://community.deeplearning.ai/t/c1-w3-assignment-unq-c1-error-wrong-shape-wrong-output/144445/8 "2022-06-28T19:18:56Z")

</div>

Hi @cagschwarz,

Glad you could resolve it on your own.

Cheers,  
Mubsi

---

<div class="post-metadata">

**Author:** ![Amrita](https://avatars.discourse-cdn.com/v4/letter/a/dc4da7/32.png) [@Amrita](https://community.deeplearning.ai/u/Amrita)\
**Post date:** [July 10, 2022, 6:47pm UTC](https://community.deeplearning.ai/t/c1-w3-assignment-unq-c1-error-wrong-shape-wrong-output/144445/9 "2022-07-10T18:47:05Z")

</div>

Hi @Mubsi ,  
Lab ID gzghtoqn  
I am stuck with errors for quite a while now. My course deadline is tonight so any help is appreciated.  
Error: Wrong output. for variable in position 0.  
Error: Wrong output. for variable in position 1.

The surprising bit is that the next section displays the expected MRI image accurately. So, I’m not sure what I’m missing.

Thank you!

---

<div class="post-metadata">

**Author:** ![Mubsi](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/mubsi/32/94983_2.png) [@Mubsi](https://community.deeplearning.ai/u/Mubsi)\
**Post date:** [July 13, 2022, 6:58am UTC](https://community.deeplearning.ai/t/c1-w3-assignment-unq-c1-error-wrong-shape-wrong-output/144445/10 "2022-07-13T06:58:21Z")

</div>

Hi @Amrita,

My apologise for getting back to you this late.

I was looking at your assignment, and I’m happy to see that you passed all of the tests.

Let me know if there’s anything else I could help you with.

Happy learning,  
Mubsi

---

<div class="post-metadata">

**Author:** ![Amrita](https://avatars.discourse-cdn.com/v4/letter/a/dc4da7/32.png) [@Amrita](https://community.deeplearning.ai/u/Amrita)\
**Post date:** [July 13, 2022, 10:08am UTC](https://community.deeplearning.ai/t/c1-w3-assignment-unq-c1-error-wrong-shape-wrong-output/144445/11 "2022-07-13T10:08:57Z")

</div>

Hi @Mubsi ,

Thanks for getting back. The issue was just the +1 was missing in the array slicing.

Yep, passed the course and received the certificate. 🙂

Amrita

---

<div class="post-metadata">

**Author:** ![cpcp](https://avatars.discourse-cdn.com/v4/letter/c/ecc23a/32.png) [@cpcp](https://community.deeplearning.ai/u/cpcp)\
**Post date:** [July 15, 2022, 8:02pm UTC](https://community.deeplearning.ai/t/c1-w3-assignment-unq-c1-error-wrong-shape-wrong-output/144445/12 "2022-07-15T20:02:04Z")

</div>

Hi @Mubsi,

I also encounter the same issue with wrong outputs

Error: Wrong output. for variable in position 0.  
Error: Wrong output. for variable in position 1.

Could you help me see if my implementation is correct?  
Lab ID okduwigi

Thanks!

---

<div class="post-metadata">

**Author:** ![Mubsi](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/mubsi/32/94983_2.png) [@Mubsi](https://community.deeplearning.ai/u/Mubsi)\
**Post date:** [July 18, 2022, 7:20am UTC](https://community.deeplearning.ai/t/c1-w3-assignment-unq-c1-error-wrong-shape-wrong-output/144445/13 "2022-07-18T07:20:26Z")

</div>

Hi @cpcp,

I’m seeing that you are already passing all of the tests in your assignment. Glad you were able to figure out your mistake.

Happy learning,  
Mubsi

---

<div class="post-metadata">

**Author:** ![Rehan\_Ahmed](https://avatars.discourse-cdn.com/v4/letter/r/ea666f/32.png) [@Rehan\_Ahmed](https://community.deeplearning.ai/u/Rehan_Ahmed)\
**Post date:** [August 27, 2022, 8:18am UTC](https://community.deeplearning.ai/t/c1-w3-assignment-unq-c1-error-wrong-shape-wrong-output/144445/14 "2022-08-27T08:18:50Z")

</div>

Hi @Mubsi ,  
Can you please take a look through my notebook , I am also getting this sort of error in 1 exercise , I have tried multiple times to figure out but didnot come to solution , kindly assists me to know where I am doing wrong as the deadline is drawing near

lab\_id : wrenygmb

Thanks

---

<div class="post-metadata">

**Author:** ![getjaidev](https://avatars.discourse-cdn.com/v4/letter/g/a3d4f5/32.png) [@getjaidev](https://community.deeplearning.ai/u/getjaidev)\
**Post date:** [November 25, 2022, 11:15am UTC](https://community.deeplearning.ai/t/c1-w3-assignment-unq-c1-error-wrong-shape-wrong-output/144445/15 "2022-11-25T11:15:58Z")

</div>

Lab ID: tsranekg

Hi @Mubsi

I the above lab session, everything seems ok, but I get this…

…  
Extracting (2, 2, 2) sub-volume

Error: Wrong shape. for variable 1.

Sampled Image:  
z = 0  
[[1. 2.]  
[2. 4.]]  
z = 1  
[[2. 4.]  
[4. 8.]]

Sampled Label:  
class = 0  
z = 0  
[[1. 1.]  
[1. 1.]]  
z = 1  
[[0. 0.]  
[0. 0.]]  
class = 1  
z = 0  
[[0. 0.]  
[0. 0.]]  
z = 1  
[[1. 1.]  
[1. 1.]]  
2 Tests passed  
1 Tests failed

The surprising bit is that the expected MRI image shows correctly. So, I’m not sure what I’m missing.

Please help urgently.

Thank you!

---

<div class="post-metadata">

**Author:** ![Mubsi](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/mubsi/32/94983_2.png) [@Mubsi](https://community.deeplearning.ai/u/Mubsi)\
**Post date:** [November 25, 2022, 2:50pm UTC](https://community.deeplearning.ai/t/c1-w3-assignment-unq-c1-error-wrong-shape-wrong-output/144445/16 "2022-11-25T14:50:18Z")

</div>

Hi @getjaidev,

You have ignored an important instruction:  
 ![Screenshot 2022-11-25 at 7.47.52 PM](https://global.discourse-cdn.com/dlai/original/3X/3/7/372670857fff9de1336abe9dba5801b2309bbf39.png)

You have not included number of classes.

When you’ll add that you’ll see your function will pass.

Cheers,  
Mubsi

---

<div class="post-metadata">

**Author:** ![getjaidev](https://avatars.discourse-cdn.com/v4/letter/g/a3d4f5/32.png) [@getjaidev](https://community.deeplearning.ai/u/getjaidev)\
**Post date:** [November 28, 2022, 3:26am UTC](https://community.deeplearning.ai/t/c1-w3-assignment-unq-c1-error-wrong-shape-wrong-output/144445/17 "2022-11-28T03:26:07Z")

</div>

Thanks @Mubsi. Worked!

---

<div class="post-metadata">

**Author:** ![Kietsakul](https://avatars.discourse-cdn.com/v4/letter/k/50afbb/32.png) [@Kietsakul](https://community.deeplearning.ai/u/Kietsakul)\
**Post date:** [March 31, 2023, 9:46am UTC](https://community.deeplearning.ai/t/c1-w3-assignment-unq-c1-error-wrong-shape-wrong-output/144445/18 "2023-03-31T09:46:36Z")

</div>

Having similar issue

lab ID : ffsjlrqmsjxy

any suggestion?

---

<div class="post-metadata">

**Author:** ![SSC13](https://avatars.discourse-cdn.com/v4/letter/s/8baadc/32.png) [@SSC13](https://community.deeplearning.ai/u/SSC13)\
**Post date:** [May 3, 2023, 7:22pm UTC](https://community.deeplearning.ai/t/c1-w3-assignment-unq-c1-error-wrong-shape-wrong-output/144445/19 "2023-05-03T19:22:06Z")

</div>

Hi I got similar situation, can you help me solve?

ID: pysgojjpurgf

error messag:  
Extracting (2, 2, 2) sub-volume

Error: Data-type mismatch.  
Error: Wrong shape.  
Error: Wrong output.

---

<div class="post-metadata">

**Author:** ![getjaidev](https://avatars.discourse-cdn.com/v4/letter/g/a3d4f5/32.png) [@getjaidev](https://community.deeplearning.ai/u/getjaidev)\
**Post date:** [May 4, 2023, 5:29am UTC](https://community.deeplearning.ai/t/c1-w3-assignment-unq-c1-error-wrong-shape-wrong-output/144445/20 "2023-05-04T05:29:34Z")

</div>

Hi @SSC13,

Welcome to the forum.

You probably missed this. I did, when i had this problem:

![372670857fff9de1336abe9dba5801b2309bbf39](https://global.discourse-cdn.com/dlai/original/3X/2/7/27bf73d2689799fd16bee4ea170e4aa67a462b23.png)

You might have not included number of classes.

Best Regards,  
– Jaidev

[Next page](https://community.deeplearning.ai/t/c1-w3-assignment-unq-c1-error-wrong-shape-wrong-output/144445.md?page=2)
