Python: How to return a result from a conditional and then have it re-enter the conditional statement -


thanks ahead of time help. having problems if else statement. below code. basically, if else:is entered means there no data , rest of code should not run. need when else:is entered need return new randx , randy values entered if (dem_arr[randx, randy] > -100):. have tried using while no success.

neighbors = [(-1,-1), (-1,0), (-1,1), (0,1), (1,1), (1,0), (1,-1), (0,-1)] mask = np.zeros_like(dem_arr, dtype = bool) stack = [(randx, randy)] # push start coordinate on stack counterstack = [(randx, randy)]  if (dem_arr[randx, randy] > -100):     count = 0     while count <= 121:         x, y = stack.pop()         mask[x, y] = true         dx, dy in neighbors:             nx, ny = x + dx, y + dy             if (0 <= nx < dem_arr.shape[0] , 0 <= ny < dem_arr.shape[1] , dem_arr[x, y] > -100 , dem_arr[nx, ny] > -100 , not mask[nx, ny] , abs(dem_arr[nx, ny] - dem_arr[x, y]) <= 5):    #set elevation differnce                 stack.append((nx, ny))  #if point selected (true) array position gets added stack , process runs on again                 if ((nx, ny) not in counterstack):                     counterstack.append((nx, ny))                      dem_copy[(nx, ny)] = 8888                     dem_copy[randx, randy] = 8888                     count += 1 else:   #if enters else need new randx , new randy points need returned , re-enter above if(dem_arr...)     print 'point chosen has no data'     randx = random.randint(0, row-1)     randy = random.randint(0, col-1) 

thanks help.

-r

modify code this.

before:

if (dem_arr[randx, randy] > -100):     ... else:     ... 

after:

while(true):     if (dem_arr[randx, randy] > -100):         ...         break#break while-loop.     else:         ...         continue#go , continue while-loop. 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

inno setup - TLabel or TNewStaticText - change .Font.Style on Focus like Cursor changes with .Cursor -