I have a numpy array, and it is defined like this-
arr = np.random.randint(20, size = (10,10))
and I want to return a random sequence in that array. The output of the array could be something like
[[ 5 19 2 12 6 3 2 3 1 18]
[ 2 14 19 10 7 0 13 3 6 16]
[ 9 3 14 15 0 18 19 11 0 14]
[10 18 10 7 2 17 12 13 8 9]
[ 2 6 8 16 13 6 13 17 10 2]
[ 4 2 11 12 10 13 10 18 14 5]
[11 1 0 0 19 15 8 11 7 15]
[ 7 10 4 2 1 9 19 1 10 16]
[ 0 1 9 5 7 1 13 18 2 10]
[ 1 13 8 7 13 10 7 6 11 6]]
and I would want to return something like 5, 2, 9, 3, 18, 6, 2, 11 0, 4 etc. Here is what I have tried-
def path():
paths = []
actions = np.random.randint(4, size = 50)
for ix,iy in np.ndindex(room.shape):
for i in actions:
if i == 0:
state = room[ix - 1][iy]
paths.append(state)
elif i == 1:
state = room[ix + 1][iy]
paths.append(state)
elif i == 2:
state = room[ix][iy - 1]
paths.append(state)
elif i == 3:
state = room[ix][iy + 1]
paths.append(state)
print(paths)
And this does not work.