{{{id=18| #r=[1/2,1,1/2] r=[1/32, 0, -1/4, 1/2, 23/16, 1/2, -1/4, 0, 1/32] s=[] for i in range(len(r)): s.append(N(r[i])) print s /// [0.0312500000000000, 0.000000000000000, -0.250000000000000, 0.500000000000000, 1.43750000000000, 0.500000000000000, -0.250000000000000, 0.000000000000000, 0.0312500000000000] }}} {{{id=17| %cython s=[.5,1,.5] #C is going to turn fractions into integers. So use decimals. #s= [0.0312500000000000, 0.000000000000000, -0.250000000000000, 0.500000000000000, 1.43750000000000, 0.500000000000000, -0.250000000000000, 0.000000000000000, 0.0312500000000000] import numpy D=1000 #Detail - The reciprocal of the step size. Iter=15 #Number of iterations Supp=len(s)-1 #Support length of phi X=numpy.linspace(0,2*Supp,2*Supp*D+1) P=numpy.zeros((Iter,len(X))) #The matrix of approximation values for k in xrange(0,D): P[0,k]=1 def Iterate(P): Q=P cdef unsigned int n, k, m for n in xrange(0,Iter-1): for k in xrange(0,(len(X)-1)/2): for m in xrange(0,len(s)): Entry=2*k-D*m-1 if (Entry >= 1) and (Entry < ((len(X)-1))/2): Q[n+1,k]=Q[n+1,k]+s[m]*Q[n,Entry] return Q Q=Iterate(P) ####################### import numpy import pylab pylab.plot(X[:], Q[Iter-1,:]) pylab.grid(True) pylab.savefig('simple_plot') pylab.show() /// }}} {{{id=5| from numpy import * A = array(([1,2,3,4],[2,2,2,2])) B = ones((4,2)) print A print B dot(A[1,:],B[:,1]) /// }}}