0

I am trying to get a matrix that contains the distances between the points in two lists.

The vector of points contain the latitude and longitude, and the distance can be calculated between any two points using the euclidean function

I've managed to calculate between two specific coordinates but need to iterate through the lists for every possible store-warehouse distance.

Any suggestions on how to proceed? :)

wh_coords=[(134,104),(141,82),(128,29),(120,49),(56,104),(14,60),(16,51),(17,94),(50,102),(44,99)]
st_coords=[(53,138),(79,130),(72,76),(53,3),(85,111),(102,39),(122,18),(147,7),(40,150),(46,19),(57,19),(88,113)]

import math
def calc_euc_dist(point_1, point_2): 
   distance = math.sqrt((point_1[0] - point_2[0])**2 + (point_1[1] - point_2[1])**2)
   return(distance)
   
point_1=(134,53)
point_2=(104,138)

distance1_2=calc_euc_dist(point_1, point_2)
print(distance1_2) ยดยดยด
AOL
  • 1

1 Answers1

0

itertools.product

Specifically:

import itertools
for point_1,point_2 in itertools.product(wh_coords, st_coords):
    print(point_1,point_2, calc_euc_dist(point_1, point_2))

https://docs.python.org/3/library/itertools.html#itertools.product

SamBob
  • 849
  • 6
  • 17