Lowest cost through this matrix:
Traceback (most recent call last):
File "muncre.py", line 8, in <module>
print_matrix(matrix, msg='Lowest cost through this matrix:')
File "/usr/lib/python2.7/dist-packages/munkres.py", line 730, in print_matrix
width = max(width, int(math.log10(val)) + 1)
ValueError: math domain error
マトリックスのいずれかの行にゼロが含まれている場合、上記のエラーがスローされます。どうすれば修正できますか?
これは、Python のコードの一部です。
from munkres import Munkres, print_matrix
matrix = [[6, 9, 1],
[10, 9, 2],
[0,8,7]]
m = Munkres()
indexes = m.compute(matrix)
print_matrix(matrix, msg='Lowest cost through this matrix:')
total = 0
for row, column in indexes:
value = matrix[row][column]
total += value
print '(%d, %d) -> %d' % (row, column, value)
print 'total cost: %d' % total
Ubuntu で次のコマンドを使用して、ライブラリ munkres をインストールしました。
sudo apt-get install python-munkres