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

c - Compilation of a code: unkown type name string -

java - Bypassing "final local variable defined in an enclosing type" -

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