[Numpy-discussion] Operation over multiple axes? (Or: Partial flattening?)
Stéfan van der Walt
Tue Jul 29 14:47:52 CDT 2008
2008/7/29 Hans Meine <email@example.com>:
> On Dienstag 29 Juli 2008, Stéfan van der Walt wrote:
>> > One way to achieve this is partial flattening, which I did like this:
>> > dat.reshape((numpy.prod(dat.shape[:3]), dat.shape)).sum(0)
>> > Is there a more elegant way to do this?
>> That looks like a good way to do it. You can clean it up ever so slightly:
>> x.reshape([-1, x.shape[-1]]).sum(axis=0)
> Thanks, that looks more elegant indeed. I am not sure if I've read about -1
> in shapes before. I assume it represents "the automatically determined rest"
> and may only appear once? Should this be documented in the reshape
That's correct, and yes -- it should! Would you like to document it
yourself? If you register on
I'll give you editor's access.
More information about the Numpy-discussion