What are the Python types accepted by MATLAB?

6 vues (au cours des 30 derniers jours)
MathWorks Support Team
MathWorks Support Team le 12 Avr 2019
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?

Réponse acceptée

MathWorks Support Team
MathWorks Support Team le 12 Avr 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

Plus de réponses (0)

Catégories

En savoir plus sur Call Python from MATLAB dans Help Center et File Exchange

Produits


Version

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by