fchollet / nelder-mead

Pure Python/Numpy implementation of the Nelder-Mead algorithm.
GNU General Public License v2.0
122 stars 42 forks source link

'tuple' object does not support item assignment #1

Closed userstring closed 9 years ago

userstring commented 9 years ago

I am trying with a very simple example as follows:

import nelder_mead as NM from numpy import array def my_fun(x): p_1= x[0] p_2= x[1] p_3= x[2] x_2 = 0.23; x_1 = 7.2; x_3 = 3.2; o_2 = 0.03; o_1 = 0.87; o_3 = 0.2; return ((x_1-p_1)/o_1)2 + ((x_2-p_2)/o_2)2 + ((x_3-p_3)/o_3)**2

vec0= (0,0,0) NM.nelder_mead(my_fun,vec0 )

if I run this it says " in nelder_mead.py", line 32, in nelder_mead x[i] = x[i] + step TypeError: 'tuple' object does not support item assignment "

Any help would be highly appreciated.

fchollet commented 9 years ago

You seem unfamiliar with the Python syntax... your function is not syntactically correct.

The error you're seeing is due to your initial vec0 being a tuple: it should be a numpy array.