I would like to prepare a list of 3 randomly generated hub stations and 25 randomly generated stations, and then generate a list excluding the stations included in a certain radius circle of 3 hub stations. Is calculated only for the last element.
I know that I'm a beginner and stumbling in a rudimentary place, but I'd appreciate it if someone could tell me.
def remove_station (station_list, hub_list, R_big): X, Y = hub_list , hub_list  x, y = station_list , station_list  hub_size = len (hub_list ) station_size = len (station_list ) for i in range (hub_size): for j in range (station_size): Dx = X [i]-x [j] Dy = Y [i]-y [j] b = math.sqrt (Dx * Dx + Dy * Dy) m =  n =  if b-R_big>= 0: # If the distance between the station and the base station is more than R_big, it will be adopted as a station m.append (x [j]) n.append (y [j]) else: pass return [m, n]
Answer # 1
The list m, n has been initialized after exiting the double loop, so only the last entry can enter m, n.
It is before the double loop that m and n are initialized.
Need to determine if the distance between a station and all hub stations is more than R_big
Because there is a double loop, the list of normal stations is outside and the list of hub stations is inside.
If you use random data without knowing whether the program is written correctly,
It becomes difficult to verify the program.
I corrected it based on that point. Please see below.
The coordinates of the hub station are as follows.
The coordinates of a normal station are as follows.
The radius R_big is 25.
As you can see by writing a picture, the two stations (25,75) and (25,60) are far from any hub station.
import math def remove_station (station_list, hub_list, R_big): X, Y = hub_list , hub_list  x, y = station_list , station_list  hub_size = len (hub_list ) station_size = len (station_list ) m =  n =  for j in range (station_size): flag = True for i in range (hub_size): Dx = X [i]-x [j] Dy = Y [i]-y [j] b = math.sqrt (Dx * Dx + Dy * Dy) if b<= R_big: # If the distance between a hub station and the station is within R_big, # Since it is not adopted as a station, set False to flag flag = False if flag == True: # A station that is more than R_big away from any hub station # Add to list m, n m.append (x [j]) n.append (y [j]) return [m, n] (station_list_x, station_list_y) = remove_station ([[25,75,75,25,25], [20,30,60,75,60]], [[25,75,75], [25,25,75] ],twenty five) print ('x =') print (station_list_x) print ('y =') print (station_list_y)
The execution result is as follows.
x = [25, 25] y = [75, 60]
I'm glad if you can use it as a reference.
Answer # 2
Impressions I saw briefly.
I don't think it will work because there is no if statement in the for statement.
- i'm having a problem because the result is not displayed in python
- python - assertionerror solution
- python heat map cannot be read because the axis scale interval is narrow
- solution for error unexpected indent (python)
- python - i don't know the solution and cause of the attribute error that occurred when using pillow
- python - please tell me the solution of gunicorn: command not found when deploying heroku (crying)
- getoldtweets-error solution for python
- python - i am in trouble because the cause of attributeerror is unknown
- python - i am in trouble because the cause of invalid syntax is unknown
- python - please let me know because there is something i don't understand
- "openpyxl" cannot be imported in python
- python - launch jupyterlab/notebook from the terminal
- python - something went wrong in the jupiter lab
- python 3x - i want to resolve the error typeerror: loop of ufunc does not support argument 0 of type float which has no callable
- python - modelpredict() cannot be executed in tensorflow
- macos (osx) - sort_valus method error macos
- please add a python error
- i'm trying to create a scientific calculator with jupyter's python, but i want to add exponentiation, factorial, function, log,
- python - missing 1 required positional argument error
- python 3x - i want to display the importance extracted by evaluating with random forest as a column graph