Search code examples
pythonarraysnumpyscipyminimize

Python: numpy and scipy minimize: setting an array element with a sequence minimize


I'm trying to minimize the function, but get an

ValueError: setting an array element with a sequence.

in the following code:

import numpy as np
from scipy import optimize as opt

def f(x):
    return np.sin(x / 5.) * np.exp(x / 10.) + 5 * np.exp( -x / 2.)

aprox_0 = np.array([range(1, 10), range(11, 20), range(21, 30)])
min_0 = opt.minimize(f, aprox_0[0])

Can anyone help?


Solution

  • Check the dimensions of both x inside the function f() and its returning value during the mininization, when you find the problem probably the function flatten() will help.