相关疑难解决方法(0)

在python中创建Matlab单元格数组

我正在尝试在python中创建一个Matlab单元格数组并将其保存为.mat文件,但是当所有单元格包含2个值时遇到问题:

import scipy.io as sio

twoValues = {'a': array([[array([[2, 2]]), array([[3, 3]])]])}
sio.savemat('test.mat',twoValues)
Run Code Online (Sandbox Code Playgroud)

在Matlab中:

load('test.mat')
>>> a

a(:,:,1,1) =

           2           3


a(:,:,1,2) =

           2           3


>>> class(a)

ans =

int32
Run Code Online (Sandbox Code Playgroud)

回到python:

threeValues = {'a': array([[array([[2, 2, 2]]), array([[3, 3]])]])}
sio.savemat('test.mat',threeValues)
Run Code Online (Sandbox Code Playgroud)

在Matlab中:

>>> a

a = 

    [3x1 int32]    [2x1 int32]


>>> class(a)

ans =

cell
Run Code Online (Sandbox Code Playgroud)

这是什么原因?

python matlab scipy

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

matlab ×1

python ×1

scipy ×1