[Numpy-discussion] summing over more than one axis

greg whittier gregwh@gmail....
Thu Aug 19 09:57:19 CDT 2010


On Thu, Aug 19, 2010 at 10:12 AM, Angus McMorland <amcmorl@gmail.com> wrote:
> Another rank-generic approach is to use apply_over_axes (you get a
> different shape to the result this way):
>
> a = np.random.randint(20, size=(4,3,5))
> b = np.apply_over_axes(np.sum, a, [1,2]).flat
> assert( np.all( b == a.sum(axis=2).sum(axis=1) ) )
>

Thanks for the responses!  This looks like what I've been looking for.
There's really a lot to numpy.  It's very powerful and I feel like
I've only scratched the surface.


More information about the NumPy-Discussion mailing list