# hungarian algorithm python

>>> cost = np.array([[4, 1, 3], [2, 0, 5], [3, 2, 2]]) >>> from scipy.optimize import linear_sum_assignment >>> row_ind, col_ind = linear_sum_assignment(cost) >>> col_ind array([1, 0, 2]) >>> cost[row_ind, col_ind].sum() 5

**Here is what the above code is Doing:**

1. We have a cost matrix, which is a 2D array.

2. We want to find the assignment of rows to columns that minimizes the cost.

3. The linear_sum_assignment function returns the row and column indices of the optimal assignment.

4. The optimal assignment is the assignment that minimizes the sum of the cost matrix.