![]() | Consider a recursion scheme like \] (which arises from a one-dimensional diffusion equation) |
![]() | Straightforward (slow) Python implementation:
n = size(u)-1 for i in xrange(1,n,1): u_new[i] = beta*u[i-1] + (1-2*beta)*u[i] + beta*u[i+1] |
![]() | Slices enable us to vectorize the expression:
u[1:n] = beta*u[0:n-1] + (1-2*beta)*u[1:n] + beta*u[2:n+1] |
![]() | Speed-up: factor 10--150 (150 for 3D arrays) |