I have a dataframe which holds covariance data, hence we have a square matrix. I translate this dataframe into numpy and then to list as below, so that I can use it with the matlab api:
import matlab.engine
eng = matlab.engine.start_matlab()
covdata_list = covdata.values.tolist()
covdata_MATLAB = matlab.double(covdata_list)
Then I create an anonymous function from python using the matlab api as follows, which does the simplest task ever:
eng.eval(f"obj_func = @(x) x;", nargout=0)
All good so far, BUT when I send the covariance data-translated in MATLAB's format- i.e. covdata_MATLAB
the following happens:
returns = eng.eval(f'obj_func({covdata_MATLAB})', nargout=1)
eng.size(returns)
>>>> matlab.double([[1.0,15625.0]])
While:
eng.size(covdata_MATLAB)
>>>> matlab.double([[125.0,125.0]])
As we can see it as if it "flattens" the covariance and produces a row vector of 1 X (125*125)
.
Is there a workaround or is there something I am missing?