문제

I want to compute the integral image. for example

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

This will generate another array b.Can I execute the cumsum in-place. If not . Are there any other methods to do that

도움이 되었습니까?

해결책

You have to 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 along the rows and axis=1 to sum along the columns.

다른 팁

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

a=array([(1,2,3)])
b = np.cumsum(a)
print b
>>array([1,3,6]) 
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top