I have a following question. I have a function get_time that return time between two coordinates. I would like to create a time matrix.
Here is my code:
def time_matrix(coordinates):
times = np.zeros((len(coordinates), len(coordinates)), dtype=float)
for i in range(len(coordinates)):
for j in range(len(coordinates)):
time = get_time(
coordinates[i][0], coordinates[i][1], coordinates[j][0], coordinates[j][1]
) / 60
times[i][j] = time
return times.tolist()
My function works, but it is very ineffective. times is symmetric, so it would be better to use each time twice. In other words, I don`t want to compute the result row by row. Can you help me how can I modify my function, please?