0

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?

3
  • Can you explain what you expect to happen if you feed an array as initial guess? The code works if you replace aprox_0[0] with a single value. Maybe you are just mistaken about the shape of aprox_0? It's a 2D array. Commented May 22, 2017 at 10:22
  • This question has a better answer: stackoverflow.com/questions/22844347/… Commented May 22, 2017 at 10:39
  • Thanks guys, I've found the issue: I thought about the finding local minimum via arrays and using them as a parameter instead of boundaries Commented May 22, 2017 at 11:05

1 Answer 1

0

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.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.