Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add conversion to list before padding, extend length of result #38

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

giuliabaldini
Copy link

@giuliabaldini giuliabaldini commented Sep 21, 2020

Hi, I've been using this repository for some time now and I found two things that did not work for me.

First, when passing a non-square numpy ndarray to the Munkres.compute() function, an error occurs because numpy arrays are not extendable. However, this only happens when there are more rows than columns because the column extension does not modify the original array.

from munkres import Munkres
import numpy as np

m = Munkres()

arr = np.array([[10, 2, 3],
                [4, 5, 7],
                [8, 9, 10],
                [11, 0, 1]])
munkres_tuples = m.compute(arr)
print(munkres_tuples)

So with this code we get:

  File "", line 202, in __step1
    if self.C[i][j] is not DISALLOWED:
IndexError: index 3 is out of bounds for axis 0 with size 3

because the array has not been padded correctly.
The solution to this is changing line 103 from new_row = row[:] to new_row = list(row[:]), which is then extendable and can be padded correctly. Moreover, if row[:] is a list already, then nothing will happen.

The second thing is the output solution. The output of the above program is:

[(0, 2), (1, 0), (3, 1)]

However, since there is an additional row, we would like to also have the assignment for that row. This can be fixed by changing line 166 from self.original_length to self.n and line 167 from self.original_width to self.n. Then we obtain:

[(0, 2), (1, 0), (2, 3), (3, 1)]

Edit about this second part: I checked the tests and they fail for this second part because the _get_cost definition. I'm not sure if this is a feature that people need, but it's definitely something I personally needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant