Finding means and stds of a bunch of torch.Tensors (that are converted from ndarray images)
to_tensor = transforms.ToTensor()
img = to_tensor(train_dataset[0]['image'])
img

Converts my images values between 0 and 1 which is expected.  It also converts img which is an ndarray to a torch.Tensor.
Previously, without using to_tensor (which I need it now), the following code snippet worked (not sure if this is the best way to find means and stds of the train set, however now doesn't work. How can I make it work?
image_arr = []

for i in range(len(train_dataset)):
    image_arr.append(to_tensor(train_dataset[i]['image']))

print(np.mean(image_arr, axis=(0, 1, 2)))
print(np.std(image_arr, axis=(0, 1, 2)))

The error is:
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
&lt;ipython-input-147-0e007c030629&gt; in &lt;module&gt;
      4     image_arr.append(to_tensor(train_dataset[i]['image']))
      5 
----&gt; 6 print(np.mean(image_arr, axis=(0, 1, 2)))
      7 print(np.std(image_arr, axis=(0, 1, 2)))

&lt;__array_function__ internals&gt; in mean(*args, **kwargs)

~/anaconda3/lib/python3.7/site-packages/numpy/core/fromnumeric.py in mean(a, axis, dtype, out, keepdims)
   3333 
   3334     return _methods._mean(a, axis=axis, dtype=dtype,
-&gt; 3335                           out=out, **kwargs)
   3336 
   3337 

~/anaconda3/lib/python3.7/site-packages/numpy/core/_methods.py in _mean(a, axis, dtype, out, keepdims)
    133 
    134 def _mean(a, axis=None, dtype=None, out=None, keepdims=False):
--&gt; 135     arr = asanyarray(a)
    136 
    137     is_float16_result = False

~/anaconda3/lib/python3.7/site-packages/numpy/core/_asarray.py in asanyarray(a, dtype, order)
    136 
    137     &quot;&quot;&quot;
--&gt; 138     return array(a, dtype, copy=False, order=order, subok=True)
    139 
    140 

ValueError: only one element tensors can be converted to Python scalars


Here is a working example:
import torch
from torchvision import transforms
train_dataset = torch.rand(100, 32, 32, 3)
image_arr = []
to_tensor = transforms.ToTensor()

for i in range(len(train_dataset)):
    # to tensor will give you a tensor which is emulated here by reading the tensor at i
    image_arr.append(train_dataset[i])

print(torch.mean(torch.stack(image_arr, dim=0), dim=(0, 1, 2)))
print(torch.std(torch.stack(image_arr, dim=0), dim=(0, 1, 2)))

What did I do?
I used torch.stack to concatenate image array into a single torch tensor and use torch.mean and torch.std to compute stats. I would not recommend converting back to numpy for the purpose of evaluating stats as it can lead to unnecessary conversion from GPU to CPU.
More information on which dimension is the channel:
The above example assumes the last dimension is the channel and the image is 32x32x3 with 100 batch size. This is usually the case when the image is loaded using PIL (pillow) or numpy. Images are loaded as HWC (height width channel) in that case. This also seems to be the dimension in the question asked looking at the code example.
If the image tensor is CHW format, then you should use
print(torch.mean(torch.stack(image_arr, dim=0), dim=(0, 2, 3)))
print(torch.std(torch.stack(image_arr, dim=0), dim=(0, 2, 3)))

Torch tensors are usually CHW format as Conv layers expect CHW format. This is done automatically when the toTensor transform is applied to an image (PIL image). For complete rules see documentation of toTensor here.
