You can pass the keepdims argument to use broadcasting:
images = (images - images.mean(dim = [1,2,3], keepdims=True)) / images.std(dim=[1,2,3], keepdims=True)




 enterthevoidf22:

if i want to standardize each color matrix separately, meaning for each image i extract mean and std of each color and subtract by that separately - how do i do that?


Wouldn’t that be the standard normalization applied in batchnorm layers?
If so, you could use your code and use dim=[0, 2, 3] instead.