def linear_sum_assignment(cost_matrix):
 cost_matrix = np.asarray(cost_matrix)
 if (len(cost_matrix.shape) != 2):
  raise ValueError(('expected a matrix (2-d array), got a %r array' % (cost_matrix.shape,)))
 if (cost_matrix.shape[1] < cost_matrix.shape[0]):
  cost_matrix = cost_matrix.T
  transposed = True
 else:
  transposed = False
 state = _Hungary(cost_matrix)
 step = (None if (0 in cost_matrix.shape) else _step1)
 while (step is not None):
  step = step(state)
 if transposed:
  marked = state.marked.T
 else:
  marked = state.marked
 return np.where((marked == 1))

def linear_sum_assignment ( cost_matrix ) : cost_matrix = np . asarray ( cost_matrix ) if ( len ( cost_matrix . shape ) != 2 ) : raise ValueError ( ( 'expected a matrix (2-d array), got a %r array' % ( cost_matrix . shape , ) ) ) if ( cost_matrix . shape [ 1 ] < cost_matrix . shape [ 0 ] ) : cost_matrix = cost_matrix . T transposed = True else : transposed = False state = _Hungary ( cost_matrix ) step = ( None if ( 0 in cost_matrix . shape ) else _step1 ) while ( step is not None ) : step = step ( state ) if transposed : marked = state . marked . T else : marked = state . marked return np . where ( ( marked == 1 ) )
solve the linear sum assignment problem .