The (-1,-2) are the dimensions in which the mean will be calculated. -1 is the last dimension and -2 is the second to last dimension. Specifying the (-1,-2) dimensions will give you the same answer as just calling .mean() if your array is 2 dimensional, but if it is more than 2 dimensions then you will get a different answer.

If you have an 2 dimensional picture/array of shape x by y and you call .mean() on it or call .mean((-1,-2)) on it it will give you the same result, but if you ‘batch’ up your ‘pictures/arrays’ into an array so your new array is (# of images in batch) by x by y, then calling .mean() would give you the mean of all of the pictures (single number returned) but calling .mean((-1,-2)) will give you the mean of each picture in the batch so the return value would be the size of your batch. It’s essentially allowing the function to work on both single ‘images’ and batches of ‘images’.

Hopefully this screenshot illustrates what is happening…