# How to convert a 1x5x5600 cell in MATLAB to a python list that is (1,5,5600)

28 ビュー (過去 30 日間)
Julia Gorman 2022 年 8 月 3 日

I have a cell in MATLAB is 1x5x5600 and I need to convert it so I can use it in python and it would be easiest if it were in a list that is dimensions (1,5,5600)
##### 1 件のコメント表示非表示 なし
Matt J 2022 年 8 月 3 日

Python lists are always 1D, I believe. Only NumPy arrays have an actual shape.
Why would it help to make the list 3D?

サインインしてコメントする。

### 回答 (1 件)

Al Danial 2022 年 8 月 5 日
Lists, like cell arrays, may be nested so @J C's request is doable. Here's an example with a 1x3x5 cell:
% create the cell array
a = cell(1,3,5);
for r = 1:3
for c = 1:5
a{1,r,c} = r*1000 + c;
end
end
% convert it to an equivalent, similarly shaped Python list
py_a = py.list();
py_a_level1 = py.list();
for r = 1:3
py_a_level2 = py.list();
for c = 1:5
py_a_level2.append( a{1,r,c} );
end
py_a_level1.append( py_a_level2 );
end
py_a.append( py_a_level1 );
In Python, py_a looks like this:
In : py_a
Out:
[[[1001.0, 1002.0, 1003.0, 1004.0, 1005.0],
[2001.0, 2002.0, 2003.0, 2004.0, 2005.0],
[3001.0, 3002.0, 3003.0, 3004.0, 3005.0]]]
In : py_a[0][1][2]
Out: 2003.0

サインインしてコメントする。

### カテゴリ

Find more on Call Python from MATLAB in Help Center and File Exchange

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by