python/Matlab interoperability

1 view (last 30 days)
Marco Halder
Marco Halder on 28 Mar 2019
Answered: Dhruv on 2 Jan 2025
Hi,
The current matlab implementation uses the python `array.array` class, when calling python code from matlab. This is quite inconvenient, since almost nobody in the python world uses `array.array`. The defacto standard is numpy. Are there any plans to enhance interoperability? In particular, the handling of complex data is currently not ideal.
Best regards

Answers (1)

Dhruv
Dhruv on 2 Jan 2025
I understand that you would like to use Python's 'NumPy' since handling complex data is not ideal upon using 'array.array', which is just a memory view representation. MATLAB uses 'array.array' because it does not assume that the target machine uses 'NumPy'. Additionally, if the user does not want to use 'NumPy', then it is convenient to use 'array.array'.
However, it is quite easy to convert an 'array.array' into 'NumPy' array in MATLAB. The following example declares an 'array.array', and then converts it into 'NumPy' array.
xA = py.array.array('d',[1,2,3])
xNA = py.numpy.array(xA)
I hope this helps!

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!