|
import numpy as np |
|
|
|
|
|
def find_exact_match(matrix, query_vector, decimals=9): |
|
""" |
|
Finds the index of the vector in 'matrix' that is the closest match to 'query_vector' |
|
when considering rounding to a specified number of decimal places. |
|
|
|
Parameters: |
|
- matrix: 2D numpy array where each row is a vector. |
|
- query_vector: 1D numpy array representing the vector to be matched. |
|
- decimals: Number of decimals to round to for the match. |
|
|
|
Returns: |
|
- Index of the exact match if found, or -1 if no match is found. |
|
""" |
|
|
|
rounded_matrix = np.round(matrix, decimals=decimals) |
|
rounded_query = np.round(query_vector, decimals=decimals) |
|
|
|
|
|
matches = np.all(rounded_matrix == rounded_query, axis=1) |
|
|
|
|
|
if np.any(matches): |
|
return np.where(matches)[0][0] |
|
else: |
|
return -1 |