In the version at least version 1.7.1, mean supports a tuple of axes for the axis parameter, although this function is not documented. I believe this is an example of outdated documentation, and not something you should not rely on, since similar procedures, such as sum , document the same function. However, use at your own risk:
mean = data.mean(axis=(2, 3))
If you do not want to use undocumented functions, you can simply do two passes:
mean = data.mean(axis=3).mean(axis=2)
source share