python list extension with scalars

2 ビュー (過去 30 日間)
Ilya 2015 年 9 月 30 日
コメント済み: Ilya 2015 年 10 月 1 日
I need to export a few data from MATLAB to Python via the Python engine. It's needed to transform some 1xN vectors to python lists. The problem is that N can be also 1 (or >1). Then the code below won't work.
a_py = py.list(a)
Attempting to first initialize and then extend won't work as well.
a_py = py.list(); a_py.extend(a);
Is there any way to do this in an elegant way without writing if-else conditions?


Robert Snoeberger
Robert Snoeberger 2015 年 9 月 30 日
You could pass a cell array.
a_py = py.list(num2cell(a))
  1 件のコメント
Ilya 2015 年 10 月 1 日
Yes, very good!


その他の回答 (0 件)


Help Center および File ExchangeCall Python from MATLAB についてさらに検索


Community Treasure Hunt

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

Start Hunting!

Translated by