【发布时间】:2017-04-11 06:14:33
【问题描述】:
我有一系列 numpy 数组,我想将它们保存在 .mat 文件中,以便稍后绘制数据。 (我不想使用 Pickle,因为我的实际程序要复杂得多,并且有超过 2 个数组。)我的 MWE 是:
import numpy as np
import mat4py as m4p
x = np.array([1,20,0.4,0.5,9,8.8])
y = np.array([0.3,0.6,1,1,0.01,0.7])
data = {'x': x,
'y': y}
m4p.savemat('datafile.mat', data)
但我收到错误ValueError: Only dicts, two dimensional numeric, and char arrays are currently supported。
这是什么意思,我该如何解决?
【问题讨论】:
-
试试 scipy 的
savemat。from scipy import io; io.savemat(...)`。但它会将您的数组保存为 2d,因为这是 matlab 所期望的。 -
mat4py适用于列表而不是 numpy 数组。 scipy 建立在 numpy 之上。
标签: python arrays matlab numpy dictionary