[SciPy-User] implementing recursions
nicky van foreest
Wed Mar 31 14:03:05 CDT 2010
I'll try it. Thanks for the hint.
On 31 March 2010 00:40, <firstname.lastname@example.org> wrote:
> On Tue, Mar 30, 2010 at 5:25 PM, nicky van foreest <email@example.com> wrote:
>> Just out of curiosity, is there a smarter way to implement the
>> following recursion?
>> grid =delta = 0.001
>> end = 20
>> n = len(grid)
>> gamma = 3*grid
>> for j in range(n-1, -1, -1):
>> gamma[j] += dot(gamma[j+1:],G[1:n-j]) # G is a precomputed np.array
>> I still dislike the remaining for loop, but I do not see an easy way
>> out. Of course, it is possible to write the above as Ax = b, and use
>> np.solve, but then I have to build the matrix A, which takes more time
>> as much more memory is claimed.
>> (I also realize that I can use Z-transforms, but this appears somewhat
>> of a hassle, to say the least.)
> It looks like a case for lfilter to me, but G is full length so maybe
> it works with padding gamma with zeros. if lfilter works, then only
> in the case when G is 1d.
> (I have a hard time thinking in reverse indexed loops.)
>> SciPy-User mailing list
> SciPy-User mailing list
More information about the SciPy-User