How to normalize the whole image dataset

As the title, I want to normalize my image dataset by pre-calculated mean and standard deviation, But I found that there are saveral functions working on one image ,is there any existing api to calculate the mean and std on the whole dataset? I know my own code must be dumb and slow,may be numerical overflow. Or what’s the mathmetical relationship between instance std and sample set std?

You could pre-compute the mean and std of your data sequentially using this approach.
Would that work for you?