this is a continuation of a previous stackoverflow question here
I want to do it in 2 dimensions. I tried the following:
for i in range(pos):
    steps=0   #the steps that the particle does until it falls in  a trap
    in_pos = sc.random.randint(0, len(grid), 2)
    initial_trap=False
    while initial_trap==False:
        #the step of the particle can be one of this
        step=sc.array(random.choice([[0, 1], [1, 0], [0, -1], [-1, 0]]))          
        # Check position for edges and fix if required
        if in_pos + step > sc.size(grid) - 1:
            in_pos = 0
        elif in_pos + step < 0:
            in_pos = sc.size(grid) - 1
        else:
            in_pos += step
        # Check if it's a trap in order to stop the loop
        if grid[in_pos] == 0:
            initial_trap = True
        # If it isn't a trap, continue
        steps+=1
    steps_count.append(steps)
return steps_count
I also tried :
in_pos_x =int(sc.random.randint(0, len(grid), 1)) #initial position of particle in x axis
in_pos_y =int(sc.random.randint(0, len(grid), 1)) #initial position of particle in y axis
if  in_pos_x + step > len(grid)- 1 and in_pos_y + step > len(grid)-1:
    in_pos_x = 0
    in_pos_y = 0
elif in_pos_x + step < 0 and in_pos_y + step < 0:
    in_pos_x = len(grid)- 1
    in_pos_y = len(grid)- 1
else:    in_pos_x += step
    in_pos_y += step
if grid[in_pos_x][in_pos_y] == 0:
    initial_trap = True
And last,i tried to work with lists, not arrays.
in_pos = (scipy.random.randint(0,len(grid),2)).tolist()
step=random.choice([[0, 1], [1, 0], [0, -1], [-1, 0]])
but with no success either. I am lost here!
---------------Error messages-----------------------------
If run the program it gives me:
'The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()' at the line "if (in_pos + step) > sc.size(grid) - 1:"
If i use if sc.any(in_pos + step) > sc.size(grid) - 1: or if sc.any(grid[in_pos]) == 0: it runs but i used a print(grid[in_pos]) and I figured that it doesn't change values at all! It doesn't get the value '0', so the loop never ends.