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
Post a Comment