Pytorch :Why my dataset variance do not get the correct result?
Here is the function I wrote:

def channel_var(image_dataset):
    res = image_dataset[0]
    for image in image_dataset[1:]:
        res += image
    return tuple(map(lambda x: x/len(image_dataset),
     (torch.var(res[0]),
      torch.var(res[1]),
      torch.var(res[2]))))


then I tested it with a Normal distribution : 

m = normal.Normal(0, 3)
m.sample((1, 3, 32, 32))


And I get this wrong result : 

channel_var(list_test)

&gt;&gt;(tensor(0.0338), tensor(0.0352), tensor(0.0365))


Thank you

Your function is wrong. And that's because you are computing the average image and then computing the channel variance in the average image. I don't think you want that. You can just find the variance in each channel by using

torch.var(img, dim=[0,2,3])

assuming dim=1 is the channel dimension and img is a torch tensor. If img is not a torch tensor, you can concatenate list of imgs to make a tensor. 

You can do this as torch.var(torch.cat(img, dim=0), dim=[0,2,3]) cat operation concatenates list to a tensor. 
