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

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

ubuntu - Bash Script to Check That Files Are Being Created -