0

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)—

enter image description here

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.

1
  • instead of doing RC ([Row][column]) iteration do CR ([Column][row]) so that it will change the direction like above and for every odd colum go down the list and for every even go up or vice-versa you get it Commented Dec 25, 2024 at 7:20

1 Answer 1

1

for each dimension you have to define if it is ascending or descending and it will change from ascending to descending when it gets in the end of the array for that dimension and from descending to ascending when it gets in the first position. The idea is, vary the first dimension ascending, grow 1 in the next dimension, varry the first dimension descending, grow 1 again in second dimension. Do it until the end of the second dimension, add 1 to the third dimension, and start to descending on the second dimension... follow this until you have walked throw all the dimensions

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.