[Numpy-discussion] I hate for loops
Charles R Harris
Fri Jun 8 22:19:19 CDT 2007
On 6/8/07, Mathew Yeates <email@example.com> wrote:
> I'm looking for a more elegant way of setting my array elements
> Using "for" loops it would be
> for i in range(rows):
> for j in range(cols):
> N[i,j] = N[i-1][j] + N[i][j-1] - N[i-1][j-1]
If the initial values of the recursion are in the first row and column you
can use the result: N[i,j] = N[0,j] + N[i,0]. It's like the PDE D_xD_y N = 0
whose solution is the sum of two functions f(x) + g(y). It gets more
complicated if you are looking for a more general result.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Numpy-discussion