How do you visualize multiplications that occur with numpy whole arrays method?

Viewed 18

I am currently studying numerical methods and an inefficient way of performing calculations in numerical methods would be to iterate through arrays grid by grid like below:

    for it in range(maxit):
    for j in range(1,mesh.Nj-1):
        for i in range(1,mesh.Ni-1):
            u_new[j,i] = C_beta*(u_new[j-1,i]+u_new[j+1,i]+
                              beta_sq*(u_new[j,i-1]+u_new[j,i+1]))

Another way to do this is by using numpy whole arrays as follow:

for it in range(maxit):
    u_new[1:-1,1:-1] = C_beta*(mesh.u[:-2,1:-1]+mesh.u[2:,1:-1]+
                              beta_sq*(mesh.u[1:-1,:-2]+mesh.u[1:-1,2:]))

Both leads to the same result but I am having a hard time to visualize how the 2nd method works.

Some visualisations of how the arrays look like

How do you "read" the multiplication and addition going on in each iteration?

I hope my question make sense. Thank you :)

0 Answers
Related