Performance Issue using cell() to convert Python data types to Matlab
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Daniel
am 1 Aug. 2024
Beantwortet: Yair Altman
am 4 Aug. 2024
I have a Python list of 50,000 elements in Matlab, and using the cell() function to convert it to Matlab cell array is taking over an hour, while on my coworkers machine it takes less than a minute. We are both using Python 3.9, Matlab 2021b, and my VM is v4cpu 16G RAM. Also, when trying to pause or stop the execution of cell() Matlab freezes, and has to be forcefully shut down.
Note - The code below executed instantly in this website, but takes over an hour on Matlab 2021b installed on my local.
pyrun("py_list = list(range(50000))");
cellArray = cell(pyrun('py_list', 'py_list'));
1 Kommentar
Stephen23
am 1 Aug. 2024
Contact technical support: https://www.mathworks.com/support/contact_us.html
Akzeptierte Antwort
Yair Altman
am 4 Aug. 2024
If you are certain that the python list only contains numeric values (as in your example code), then using double() instead of cell() should be significantly faster. This results in a numeric array; if you need a cell array for any reason (although it's usually better to stick with numeric arrays for such cases), then you could always wrap the results in a call to num2cell(). The combination of num2cell(double(...)) could be 5-10x faster than cell(...), and without the num2cell() even faster.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Call Python from MATLAB finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!