Skip to content

Instantly share code, notes, and snippets.

@TheAlchemistKE
Created October 6, 2023 20:11
Show Gist options
  • Save TheAlchemistKE/43608c6af8622a7dc6843b619ecbbbc7 to your computer and use it in GitHub Desktop.
Save TheAlchemistKE/43608c6af8622a7dc6843b619ecbbbc7 to your computer and use it in GitHub Desktop.
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