python - pythonic way to apply function to object multiple times -



python - pythonic way to apply function to object multiple times -

i want repeatedly sum on varying dimensions of numpy ndarray eg.

#what i've got sumoverdims = [6 4 2 1] ndarray = n-dimensional numpy array #what want ndarray.sum(6).sum(4).sum(2).sum(1)

how can without ugly loop?

numpy's sum accepts tuple axis argument:

ndarray.sum(axis=(1,2,4,6))

python arrays numpy

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -