pyCthon
pyCthon

Reputation: 12361

finding max value in each column and row

Say you have a 2D matrix,Is there a particular algorithm or way to do this in excel or matlab that would find the max of each row and column, such that each column and each row has only one maximal number N, where summing all N would result in the largest possible sum,i.e. is a row or column has a max number that is repeated., as such with the simple example below

1 2 4          
3 1 4         
1 2 4         

the out put would be

1 2 4

3 2 4

1 2 4

Upvotes: 0

Views: 1579

Answers (1)

Ansari
Ansari

Reputation: 8218

You are looking for the maximum bipartite matching in a (complete) graph, where your matrix represents the edge weights matrix. You can compute this value using the Hungarian algorithm (MATLAB implementation available for download from File Exchange). Since you want the maximum match, negate all the numbers in your matrix and feed it to this function. You will get back two outputs - one is the (negative of) the maximum sum and the other a binary matrix with ones where the maximal elements occur in each row and column and zeros everywhere else.

Upvotes: 1

Related Questions