1

Following the answer in How to efficiently convert Matlab engine arrays to numpy ndarray?, it seems much more efficient to access the matlab engine array through the _data property. However it appears that there is no _data property when the array returned by Matlab is a 'complex single' one. Is there an equivalent fast access to the array of complex numbers ?

2
  • 1
    What version of MATLAB are you using? Prior to R2018a, complex data was stored as two separate memory blocks, one for the real component and one for the imaginary component. Since R2018a, it is stored interleaved in a single memory block. I suspect your answer will be different depending on the internal storage. Commented Jan 30, 2020 at 17:17
  • I am using R2016b. More exactly I am interfacing Python with a packaged version of Matlab code using the MCR 9.1. I am novice to Python and the Python-Matlab interface and I don't know how to see what members can be accessed from a Matlab object such as this _data. Commented Jan 31, 2020 at 8:22

1 Answer 1

0

A possible workaround is to return from Matlab two real arrays (one containing the real part, the other the imaginary part) and build back the complex value in Python

M_real, M_imag = myMatlabFunction()
M_real_np = np.array(M_real._data)
M_imag_np = np.array(M_imag._data)
M_np = M_real_np + M_imag_np*np.complex(0,1)

Then we can profit from the fast access to the _data member of each array.

I am still interested in more straightforward solution.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.