What are the Python types accepted by MATLAB?

7 visualizaciones (últimos 30 días)
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?

Respuesta aceptada

MathWorks Support Team
MathWorks Support Team el 12 de Abr. de 2019

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

Más respuestas (0)

Categorías

Más información sobre Call Python from MATLAB en Help Center y File Exchange.

Productos


Versión

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by