Quantcast
Channel: Determine neighboring cells in a two-dimensional grid with periodic conditions - Stack Overflow
Viewing all articles
Browse latest Browse all 5

Answer by Comevussor for Determine neighboring cells in a two-dimensional grid with periodic conditions

$
0
0

The lines periodicity is not working like the columns periodicity. I think you should first get the 2 cells on each side and then move up and down. I have tried this and it seems to work :

def celdas_vecinas(cell, n) :    last_row = n * (cell // n)    left_cell = last_row + ( cell - last_row - 1 ) % n    right_cell = last_row + ( cell - last_row + 1 ) % n    line = np.array( [ left_cell, cell, right_cell ] )    return np.mod( [ line + n, line, line - n ], n**2)

(I removed my previous answer as I messed up in indeces)


Viewing all articles
Browse latest Browse all 5

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>