What are the Python types accepted by MATLAB?

조회 수: 7 (최근 30일)
MathWorks Support Team
MathWorks Support Team 2019년 4월 12일
답변: MathWorks Support Team 2019년 4월 12일
I tried the following, using both MATLAB R2017b and R2017a from Python 2.7 IDLE:
>>> import numpy as np
>>> image = np.array([[1.0, 0.0, 0.0], [0.0, 1.0, 2.0]], dtype="uint8")
>>> image
array([[1, 0, 0],
[0, 1, 2]], dtype=uint8)
>>> g = eng.mean(image)
However, I received the following error:
Traceback (most recent call last):
File "<pyshell#19>", line 1, in <module>
g = eng.mean(image)
File "C:\Python27\lib\site-packages\matlab\engine\matlabengine.py", line 73, in __call__
out=_stdout, err=_stderr)
TypeError: unsupported Python data type: numpy.ndarray
Does it mean that non built-in Python types (such as NumPy) are not supported by MATLAB?

채택된 답변

MathWorks Support Team
MathWorks Support Team 2019년 4월 12일

The MATLAB interoperability features only support built-in Python types. For instance, NumPy arrays are not part of core Python and therefore they are not recognized in MATLAB.

Nevertheless, for many applications of non-built-in Python types, the MATLAB equivalent can be used. For instance, if you want to use a NumPy array, you can directly create a MATLAB Array in Python. Please find below the MATLAB documentation for it, which contains some examples about how to create multidimensional arrays as well:

https://www.mathworks.com/help/matlab/matlab_external/matlab-arrays-as-python-variables.html

추가 답변 (0개)

카테고리

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

제품


릴리스

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by