从 python 创建 .mat 文件
我有一个变量外显子 = [[[1, 2], [3, 4], [5, 6]], [[7, 8], [9, 10]]]
。我想创建一个如下所示的 mat 文件
>>
exon : [3*2 double] [2*2 double]
当我使用 python 代码执行相同操作时,它显示错误消息。这是我的 python 代码,
import scipy.io
exon = [[[1, 2], [3, 4], [5, 6]], [[7, 8], [9, 10]]]
scipy.io.savemat('/tmp/out.mat', mdict={'exon': (exon[0], exon[1])})
任何人都可以提出同样的建议,那就太好了。 提前致谢 维品TS
I have a variable exon = [[[1, 2], [3, 4], [5, 6]], [[7, 8], [9, 10]]]
. I would like to create a mat file like the following
>>
exon : [3*2 double] [2*2 double]
When I used the python code to do the same it is showing error message. here is my python code
import scipy.io
exon = [[[1, 2], [3, 4], [5, 6]], [[7, 8], [9, 10]]]
scipy.io.savemat('/tmp/out.mat', mdict={'exon': (exon[0], exon[1])})
It will be great anyone can give a suggestion for the same.
thanks in advance
Vipin T S
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您似乎希望在 Matlab 中将两个不同的数组链接到相同的变量名。那是不可能的。在 MATLAB 中,您可以拥有包含其他数组的元胞数组或结构体,但不能仅将一组数组分配给单个变量(这就是 mdict={'exon': (exon[0], exon1)) - 中没有元组的概念MATLAB。
您还需要将对象设为 numpy 数组:
这里有 scipy 文档 这里< /a> 包含如何保存不同 Matlab 类型的详细信息,但假设您需要元胞数组:
这将在 matlab 中产生以下结果:
或可能(未经测试):
You seem to want two different arrays linked to same variable name in Matlab. That is not possible. In MATLAB you can have cell arrays, or structs, which contain other arrays, but you cannot have just a tuple of arrays assigned to a single variable (which is what you have in mdict={'exon': (exon[0], exon1)) - there is no concept of a tuple in Matlab.
You will also need to make your objects numpy arrays:
There is scipy documentation here with details of how to save different Matlab types, but assuming you want cell array:
this will result in the following at matlab:
or possibly (untested):
Sage 是一款开源数学软件,旨在将 python 语法和 python 解释器与 Matlab、Octave、Mathematica 等其他工具捆绑在一起......
也许您想看看它:
Sage is an open source mathematics software which aims at bundling together the python syntax and the python interpreter with other tools like Matlab, Octave, Mathematica, etc...
Maybe you want to have a look at it: