Calculate the distance between the two endpoints of two vectors. A vector is defined as a list, tuple, or numpy 1D array. >>> float(euclidean_distance((0, 0), (2, 2))) 2.8284271247461903 >>> float(euclidean_distance(np.array([0, 0, 0]), np.array([2, 2, 2]))) 3.46410161513775
(vector_1: Vector, vector_2: Vector)
| 10 | |
| 11 | |
| 12 | def euclidean_distance(vector_1: Vector, vector_2: Vector) -> VectorOut: |
| 13 | """ |
| 14 | Calculate the distance between the two endpoints of two vectors. |
| 15 | A vector is defined as a list, tuple, or numpy 1D array. |
| 16 | >>> float(euclidean_distance((0, 0), (2, 2))) |
| 17 | 2.8284271247461903 |
| 18 | >>> float(euclidean_distance(np.array([0, 0, 0]), np.array([2, 2, 2]))) |
| 19 | 3.4641016151377544 |
| 20 | >>> float(euclidean_distance(np.array([1, 2, 3, 4]), np.array([5, 6, 7, 8]))) |
| 21 | 8.0 |
| 22 | >>> float(euclidean_distance([1, 2, 3, 4], [5, 6, 7, 8])) |
| 23 | 8.0 |
| 24 | """ |
| 25 | return np.sqrt(np.sum((np.asarray(vector_1) - np.asarray(vector_2)) ** 2)) |
| 26 | |
| 27 | |
| 28 | def euclidean_distance_no_np(vector_1: Vector, vector_2: Vector) -> VectorOut: |
nothing calls this directly
no outgoing calls
no test coverage detected