How to get the total amount of a numpy array in place

I want to calculate the integral image. eg

a=array([(1,2,3),(4,5,6)]) b = a.cumsum(axis=0) 

This will generate another b.Can array. I execute cumsum in place. If not. Are there other methods for this,

+8
python arrays numpy cumsum
source share
2 answers

You must pass the argument out :

 np.cumsum(a, axis=1, out=a) 

OBS: your array is actually a 2-D array, so you can use axis=0 to sum over rows and axis=1 to sum over columns.

+9
source share

Try this with numpy directly numpy.cumsum(a) :

 a=array([(1,2,3)]) b = np.cumsum(a) print b >>array([1,3,6]) 
-4
source share

All Articles