Basically, I have an n-dimensional array, and I want to iterate through its elements, but the iterator can only go to an adjacent element. Like this for example (with 2D array)—
Now I can think of a way to do this with 2D array for example (by editing the array itself), but I can't think of a way where any n-dimensional array can be looped through in this manner. If you have any ideas for this, it would help a lot. It doesn't need to move in that specific pattern, the only thing that's necessary is that the iterator only moves to adjacent matrix elements in each step.
Note: The reason I need to do this is that I am writing a python script to operate a QM program to run a "relaxed scan". In this, one or more bond lengths have to be constrained to specific values, and the rest of the molecule is allowed to relax. Most programs do this by taking the first supplied geometry, and changing the bond length value in that, every time. But this takes up a lot of time, because as the scan progresses, the original geometry is no longer a good guess, and more time is needed for the successive steps. The matrix here stores the constraint values. If I can make it so that the iterator moves only to adjacent matrix elements, then I can ensure that the change in coordinates is small, and the procedure is completed fast.
