123456789101112131415 |
- import math
- class VectorDistance:
- @staticmethod
- def calculate_distance(vector1, vector2):
- if len(vector1) != len(vector2):
- raise ValueError("Vectors must have the same dimensionality")
-
- squared_sum = sum((v1 - v2) ** 2 for v1, v2 in zip(vector1, vector2))
- return math.sqrt(squared_sum)
- if __name__ == '__main__':
- v1 = [1, 2, 3]
- v2 = [4, 5, 6]
- print(VectorDistance.calculate_distance(v1, v2))
|