compute_cartesic_distance.py 557 B

1234567891011121314151617
  1. from typing import Tuple, List
  2. import numpy
  3. # This file uses list_of_coordinates in a 2dimensional cartesic space.
  4. # To calculate a symmetric matrix (nxn) with n as length of the list_of_coordinates
  5. def compute_symmetric_matrix_in_cartesic_space(coordinates: List[Tuple[float, float]]):
  6. if len(coordinates) == 0:
  7. return numpy.zeros((0, 0))
  8. c = numpy.array(coordinates)
  9. m = numpy.meshgrid([range(len(c))], [range(len(c))])
  10. xy1 = c[m[0]]
  11. xy2 = c[m[1]]
  12. matrix = numpy.linalg.norm(xy1 - xy2, ord=2, axis=2)
  13. return matrix