python/Matlab interoperability
1 view (last 30 days)
Show older comments
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
0 Comments
Answers (1)
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!
0 Comments
See Also
Categories
Find more on Call Python from MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!