- accumulate integration[1]
from scipy import integrate
Z_array=integration.cumtrapz(Y,X)
- definite integration
from scipy import integrate
Z_scaler=integration.trapz(Y,X)
- for loop
# test for loop
import numpy
import pylab
x=numpy.array([-2,2,-5,5,-10,10])
s=0
for i in xrange(0,6):
if i==0:
print i
s=s+x[i]
print s
从这个测试中就可以看到,在python的for循环中,xrange(0,3)是从下标0开始的,而第二个数字3代表了循环从0开始,一共循环3个数字。所以要对数列中所有的元素完成循环,需要将第二个下标写为len(x)也即for i in xrange(0,len(x))
reference:
[1]https://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.integrate.cumtrapz.html
[2]