I have a 4-D(d0,d1,d2,d3,d4) numpy array. I want to get a 2-D(d0,d1)mean array, Now my solution is as following:
area=d3*d4
mean = numpy.sum(numpy.sum(data, axis=3), axis=2) / area
But How can I use numpy.mean to get the mean array.
In at least version 1.7.1, mean supports a tuple of axes for the axis parameter, though this feature isn't documented. I believe this is a case of outdated documentation rather than something you're not supposed to rely on, since similar routines such as sum document the same feature. Nevertheless, use at your own risk:
mean = data.mean(axis=(2, 3))
If you don't want to use undocumented features, you can just make two passes:
mean = data.mean(axis=3).mean(axis=2)
timeit and see ;)