将多个ndarray保存到mat文件scipy的每个单独内容中



如何使用scipy函数savemat将多个ndarray保存到一个mat文件中?我想知道我是否有两个矩阵叫AB,我能把它们都保存到一个result.mat吗,如下所示:

sio.savemat('result.mat', {'A':A})
sio.savemat('result.mat', {'B':B})

我这样做了,然后在MATLAB中打开result.mat,只找到矩阵B。。。A被覆盖。有什么帮助吗?

In [436]: with open('test.mat','wb') as f:  # need 'wb' in Python3
    savemat(f, {'A':np.arange(10)})
    savemat(f, {'B':np.ones((3,3))})
   .....:     
In [437]: loadmat('test.mat')
Out[437]: 
{'A': array([[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]),
 '__version__': '1.0',
 'B': array([[ 1.,  1.,  1.],
        [ 1.,  1.,  1.],
        [ 1.,  1.,  1.]]),
 '__globals__': [],
 '__header__': b'MATLAB 5.0 MAT-file Platform: posix, Created on: Fri May 13 16:38:04 2016'}

相关内容

最新更新