Python: 科学计算

  1. accumulate integration[1]
from scipy import integrate
Z_array=integration.cumtrapz(Y,X)
  1. definite integration
from scipy import integrate
Z_scaler=integration.trapz(Y,X)
  1. 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]

posted on 2017-08-07 20:28  DocNan  阅读(242)  评论(0编辑  收藏  举报

导航