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

javascript - THREE.js reposition vertices for RingGeometry -

javascript - I need to update the text of a paragraph by inline edit -

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