I am trying to combine Matlab and python scripts and figure out if I can achieve a better solution in terms of the solver-runtime. A very simple optimization problem is used just for now. But I got in trouble when I run optimizer in python. Here is Matlab code that includes the objective function:

function [f] = objective(x)
f = x(1)^2 + x(2)^2;

And this is the python script:

from scipy.optimize import minimize
import matlab.engine
import matlab



def const(x):
    return x[0]+x[1]-1



When I run this script, I always get the following error;

  File "C:\Users\ASUS\Anaconda3\lib\site-packages\matlab\engine\matlabengine.py", line 64, in __call__
    future = pythonengine.evaluateFunction(self._engine()._matlab,

TypeError: unsupported Python data type: numpy.ndarray

Even though I pass double to initial values, minimize is having a problem with the data type. Do you have any idea to get this thing work?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.