Getting the mean of multiple axis of a numpy array
numpy, python
Solution
In numpy 1.7 you can give multiple axis to `np.mean`:
d.mean(axis=tuple(range(1, d.ndim)))
I am guessing this will perform similarly to the other proposed solutions, unless reshaping the array to flatten all dimensions triggers a copy of the data, in which case this should be much faster. So this is probably going to give a more consistent performance.
Problem
In numpy is there a fast way of calculating the mean across multiple axis? I am calculating the mean on all but the 0 axis of an n-dimensional array. I am currently doing this; ``` for i in range(d.ndim - 1): d = d.mean(axis=1) ``` I'm wondering if there is a solution that doesn't use a python loop.