我想使用 Python 读取“.mtx 文件”。矩阵文件(31x31)由交通模拟工具(visum)给出。我使用了以下代码:
from scipy.io import mmread
A = mmread('./saclay/demand_visum.mtx')
我收到消息:
ValueError: not enough values to unpack (expected 5, got 1)
非常感谢您的帮助。
最佳答案
我调查了一下,发现有一个用于加载文件的库,名为 matrixconverters ,您可以使用以下命令加载 PTV Visum 矩阵:
from matrixconverters.read_ptv import ReadPTVMatrix
the_matrix = ReadPTVMatrix(filename="pathtoyourfile")
这是一个简短的答案,它适用于某些导出,不适用于其他导出,具体取决于您的格式。具体的 MTX 子格式是 .mtx 文件第一行中的文本,例如: $V;D3
格式对我不起作用,但其他人可以。
关于python - 使用Python读取矩阵文件(mtx): not enough values to unpack,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49984553/