python list extension with scalars

조회 수: 1 (최근 30일)
Ilya
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))

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by