根据
savemat
的文档:
文件名:字符串或文件对象
因此,您可以以附加模式打开文件并编写内容,例如:
io.savemat('temp.mat',{'data':np.ones(10)})
with open('temp.mat','ab') as f:
io.savemat(f, {'newdata':np.arange(5)})
print io.loadmat('temp.mat').keys()
或者完整描述:
{'data': array([[ 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.]]),
'__globals__': [],
'newdata': array([[0, 1, 2, 3, 4]]),
'__header__': b'MATLAB 5.0 MAT-file Platform: posix, Created on: Fri Mar 13 14:14:33 2015',
'__version__': '1.0'}
在https://github.com/scipy/scipy/blob/master/scipy/io/matlab/mio5.py#L34的一个注释中提到,如果数据文件中有函数,则追加可能会出现问题,但这表明如果我们仅保存数组,则追加不是问题。 但或许需要进一步搜索scipy
的问题。