mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-02-22 01:02:04 +00:00
[mypy] Add/fix type annotations for similarity search in machine learning (#4088)
* [mypy] Add/fix type annotations for similarity search in machine learning * fix annotation * fix annotation (Union) * isort
This commit is contained in:
parent
7d26ba7075
commit
d594f4556c
|
@ -8,6 +8,7 @@ returns a list containing two data for each vector:
|
||||||
2. distance between the vector and the nearest vector (float)
|
2. distance between the vector and the nearest vector (float)
|
||||||
"""
|
"""
|
||||||
import math
|
import math
|
||||||
|
from typing import List, Union
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
|
@ -30,7 +31,9 @@ def euclidean(input_a: np.ndarray, input_b: np.ndarray) -> float:
|
||||||
return math.sqrt(sum(pow(a - b, 2) for a, b in zip(input_a, input_b)))
|
return math.sqrt(sum(pow(a - b, 2) for a, b in zip(input_a, input_b)))
|
||||||
|
|
||||||
|
|
||||||
def similarity_search(dataset: np.ndarray, value_array: np.ndarray) -> list:
|
def similarity_search(
|
||||||
|
dataset: np.ndarray, value_array: np.ndarray
|
||||||
|
) -> List[List[Union[List[float], float]]]:
|
||||||
"""
|
"""
|
||||||
:param dataset: Set containing the vectors. Should be ndarray.
|
:param dataset: Set containing the vectors. Should be ndarray.
|
||||||
:param value_array: vector/vectors we want to know the nearest vector from dataset.
|
:param value_array: vector/vectors we want to know the nearest vector from dataset.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user