How to take nth order discrete sum from numpy array (total numpy.diff equivalent)
I know it is possible to take the nth order discrete difference of a numpy array using the numpy function numpy.diff()
, but is there a way to do the same with nth order discrete sum?
Let's say we have an array of numpy, A = np.arange(10)
. Expected output for 1st order discrete sum:
array([ 1., 3., 5., 7., 9., 11., 13., 15., 17.])
which i can get:
N = A.shape[0] B = np.zeros(N-1) for i in range(N-1): B[i] = A[i+1] + A[i]
But is there a function to avoid using a for loop?
+3
source to share