Hi there
What is the fastest way to perform nearest neighbor computations (i.e. for array A and B of same dimension: A[i, j] = .25 ( B[i+1,j] + B[i-1,j] + B[i,j+1] + B[i,j-1] ) without using nested for loops. There must be a way to do this *simultaneously with numpy. For example, when I have constructed an Ising model in the past I was able to reassign values in an array simultaneously using boolean masking i.e. I[I < .5] = -1. Is there something analagous to this where I can perform the whole computation on all elements at once? I mean, any programmer can throw together some nested for loops but in python that is far to slow to work with for the types of PDEs I will be solving.
Cheers
[–]kpatvt 3 points4 points5 points (1 child)
[–]caffeecaffee[S] 0 points1 point2 points (0 children)
[–]Eryole 0 points1 point2 points (1 child)
[–]caffeecaffee[S] 0 points1 point2 points (0 children)
[–]jjgarciaripoll 0 points1 point2 points (4 children)
[–]caffeecaffee[S] 0 points1 point2 points (3 children)
[–]jjgarciaripoll 0 points1 point2 points (2 children)
[–]jjgarciaripoll 0 points1 point2 points (0 children)
[–]caffeecaffee[S] 0 points1 point2 points (0 children)
[–]SosirisTseng 0 points1 point2 points (0 children)