mean = mean[:, None, None] # (3, 1, 1) img = img - mean # broadcasts to (3, 224, 224) print(mean.shape, img.shape) # torch.Size([3, 1, 1]) torch.Size([3, 224, 224])