# In C1M2\_Assignment where are the mean and std calculated from as they don't match my calculations

**URL:** <https://community.deeplearning.ai/t/in-c1m2-assignment-where-are-the-mean-and-std-calculated-from-as-they-dont-match-my-calculations/883812>\
**Category:** PyTorch: Fundamentals\
**Tags:** dl-ai-learning-platform, week-module-2\
**Created:** [November 22, 2025, 9:51pm UTC](https://community.deeplearning.ai/t/in-c1m2-assignment-where-are-the-mean-and-std-calculated-from-as-they-dont-match-my-calculations/883812 "2025-11-22T21:51:12Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![cicorias](https://avatars.discourse-cdn.com/v4/letter/c/2bfe46/32.png) [@cicorias](https://community.deeplearning.ai/u/cicorias)\
**Post date:** [November 22, 2025, 9:51pm UTC](https://community.deeplearning.ai/t/in-c1m2-assignment-where-are-the-mean-and-std-calculated-from-as-they-dont-match-my-calculations/883812/1 "2025-11-22T21:51:12Z")

</div>

in this assignment there is hardcoded  
mean = (0.1736,)  
std = (0.3317,)

however the following code shows slightly different values – how did you arrive at these hardcoded values?

train\_dataset\_raw = torchvision.datasets.EMNIST(root=data\_path, split=‘letters’,train=True, download=False)  
train\_images = train\_dataset\_raw.data.float() / 255.0  
mean1 = round(train\_images.mean().item(), 4)std1 = round(train\_images.std(unbiased=True,).item(), 4)  
print(f"Mean: {mean1}, Std: {std1}")

---

<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:** [November 23, 2025, 1:10am UTC](https://community.deeplearning.ai/t/in-c1m2-assignment-where-are-the-mean-and-std-calculated-from-as-they-dont-match-my-calculations/883812/2 "2025-11-23T01:10:53Z")

</div>

They compute the `mean` and `std` separately. They compute it after using the same method of loading the data that they show in this assignment, which used `torch.ToTensor`. That scales the data to be between 0 and 1, but perhaps their method is different than just dividing by 255.

---

<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:** [November 23, 2025, 3:01am UTC](https://community.deeplearning.ai/t/in-c1m2-assignment-where-are-the-mean-and-std-calculated-from-as-they-dont-match-my-calculations/883812/3 "2025-11-23T03:01:25Z")

</div>

[Here’s another recent thread](https://community.deeplearning.ai/t/mnist-mean-and-std/883455/3) that shows a way to compute the `mean` and `std` for MNIST in a way that gives the same numbers they showed in that assignment. You could port that code to the EMNIST case and see if you get different numbers than you did with your method.

---

<div class="post-metadata">

**Author:** ![vramesh6760](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/vramesh6760/32/121145_2.png) [@vramesh6760](https://community.deeplearning.ai/u/vramesh6760)\
**Post date:** [November 24, 2025, 6:18am UTC](https://community.deeplearning.ai/t/in-c1m2-assignment-where-are-the-mean-and-std-calculated-from-as-they-dont-match-my-calculations/883812/4 "2025-11-24T06:18:33Z")

</div>

I have a problem in EMNIST Letter-Detective. Everything was going fine till I recahed the training phase. There is an issue with the following line.

```auto
trained_model, _ = train_epoch(model, train_loader, loss_function, optimizer, device, verbose=True)
It says Type Error: 'Adam' object is not iterable. I am stuck here. Can you help?

```

---

<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:** [November 24, 2025, 3:38pm UTC](https://community.deeplearning.ai/t/in-c1m2-assignment-where-are-the-mean-and-std-calculated-from-as-they-dont-match-my-calculations/883812/5 "2025-11-24T15:38:32Z")

</div>

You must be invoking the optimizer incorrectly. One way that could happen is using square brackets instead of parens. In python, if I reference an object like this:

`myObject[value]`

it means a completely different thing than if I write it this way:

`myObject(value)`

In the first case, that means that `myObject` is “iterable” in python, e.g. a list or an array, and you are using `value` as an index to select a subset of that object.

In the second case with parens, that means `myObject` is a function and you are calling it and passing `value` as the first parameter.

It might help to show us the full exception trace that you are getting. Not the actual source code, please.

Also note that you have added this reply to a thread that has nothing to do with your question other than the fact that it is also about the EMNIST assignment (C1 M2). In general, it’s better to create a new thread for a new topic and place it in the right category, but I realize that if you are a new user, they don’t give you the trust level to create a new thread until you’ve done a few things on the forum. Also the UI actions to create a new thread are more complicated and not as clear. 🤓 Soon you’ll have the power to create your own new threads. Just something to keep in mind.

---

<div class="post-metadata">

**Author:** ![vramesh6760](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/vramesh6760/32/121145_2.png) [@vramesh6760](https://community.deeplearning.ai/u/vramesh6760)\
**Post date:** [November 24, 2025, 11:21pm UTC](https://community.deeplearning.ai/t/in-c1m2-assignment-where-are-the-mean-and-std-calculated-from-as-they-dont-match-my-calculations/883812/6 "2025-11-24T23:21:57Z")

</div>

I fixed it. It’s just I passed the arguments in the wrong order. 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:** [January 18, 2026, 3:55pm UTC](https://community.deeplearning.ai/t/in-c1m2-assignment-where-are-the-mean-and-std-calculated-from-as-they-dont-match-my-calculations/883812/7 "2026-01-18T15:55:51Z")

</div>


