MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / euclidean

Function euclidean

machine_learning/similarity_search.py:19–34  ·  view source on GitHub ↗

Calculates euclidean distance between two data. :param input_a: ndarray of first vector. :param input_b: ndarray of second vector. :return: Euclidean distance of input_a and input_b. By using math.sqrt(), result will be float. >>> euclidean(np.array([0]), np.array(

(input_a: np.ndarray, input_b: np.ndarray)

Source from the content-addressed store, hash-verified

17
18
19def euclidean(input_a: np.ndarray, input_b: np.ndarray) -> float:
20 """
21 Calculates euclidean distance between two data.
22 :param input_a: ndarray of first vector.
23 :param input_b: ndarray of second vector.
24 :return: Euclidean distance of input_a and input_b. By using math.sqrt(),
25 result will be float.
26
27 >>> euclidean(np.array([0]), np.array([1]))
28 1.0
29 >>> euclidean(np.array([0, 1]), np.array([1, 1]))
30 1.0
31 >>> euclidean(np.array([0, 0, 0]), np.array([0, 0, 1]))
32 1.0
33 """
34 return math.sqrt(sum(pow(a - b, 2) for a, b in zip(input_a, input_b)))
35
36
37def similarity_search(

Callers 1

similarity_searchFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected