0

i'm simulating an ensemble of random walkers in 2D in python, I set [x,y] coordinates of my walkers to be gaussian in a 2D grid, then use a rand array of -1 and +1 to move up down left right:

N=20 #number of walkers

Coor[:,1]=100*random(N) #X's coordinates
Coor[:,2]=100*random(N) #Y's coordinates

To do the simulation more realistic I want to impose that none of the walkers could have the same X Y coordinates as another at the same time, so as example if at certain time after random moves my coordinates array looks like this:

Coor[:,1]=([1,3,5,7,7,8,....]) 
Coor[:,2]=([4,8,3,2,2,9,....]) 

then the 4th and 5th elements have the same coordinates in X and Y so How I find when that happens and change one of the values to don't be in that situation?

1

1 Answer 1

1

Instead of updating the coordinates by adding a randomized vector of -1 and +1 to them, you could simply iterate over walkers and select a random direction from the currently available ones. This way your system never gets into invalid state so no extra checks are needed. I cannot prove it but I suspect that pure vectorized solution for the problem might not even exist.

Also, your current solution only gives the walkers 4 possible directions (the diagonals) to move to. I'm not sure if this was the intention.

1
  • thanks, i was looking for a vectorized way, but as you say I also think there's no one so i will do it iterating
    – Jared Lo
    Nov 4, 2014 at 21:40

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.