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.
- 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
- python - about the solution when "list the strings separated by commas, but do not use the commas contained in the characte
- [python] i'm having a problem because i don't know how to efficiently output the line numbers of duplicate lines in a data frame
- python - please tell me the solution of yolov3 error [filenotfounderror: [errno 2] no such file or directory:'traintxt']
- python calculated with the obtained result
- python: pygameerror solution
- python 3x - i can't convert the date ("2018/12/31") string in series to datetime with python
- python - something went wrong in the jupiter lab
- python - if unknown data is applied to the statistical model (generalized linear model) and the predicted value is output, it wi
- python 3x - i want to calculate spearson's rank correlation coefficient and p-value for a two-variable data set obtained from ex
- python 3x - error in sample program of anaphora analysis of natural language processing using spacy and neuralcoref
- import - i'm having trouble reading a folder with a specific name in jupyter notebook
- error when deleting words not specified in list when using strip in python
- python 3x - i want to make a graph plot
- python 3x - i cannot understand the error message displayed by the jupyter notebook in the process of face recognition using dee
- error when deleting a word (conjunction) using replace and strip in python and storing sentences individually in a list