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