Created
October 6, 2023 20:11
-
-
Save TheAlchemistKE/43608c6af8622a7dc6843b619ecbbbc7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from scipy.optimize import linear_sum_assignment | |
def hungarian_method(cost_matrix): | |
row_indices, col_indices = linear_sum_assignment(cost_matrix) | |
return list(zip(row_indices, col_indices)) | |
# Example usage: | |
cost_matrix = np.array([ | |
[3, 2, 7], | |
[1, 4, 6], | |
[5, 8, 9] | |
]) | |
matching = hungarian_method(cost_matrix) | |
print(matching) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment