[SciPy-user] cobyla help

Christian Kristukat ckkart at hoc.net
Sat Sep 30 20:42:31 CDT 2006


joe stano wrote:
> I am a novice who is just trying to learn about python and programming in
> general.  I am working with numpy arrays and when I run my program without
> the optimization everything seems to run ok.  However, when I include the
> optimization, when I multiply 2 arrays together (element wise not using
> dot()), I get a (ValueError: shape mismatch: objects cannot be broadcast to
> a single shape) error message that confuses me as I don't get it when I
> simply run the program and print out the results.
> 
> When I exclude the optimization, and print just the array that I pass to the
> function, it looks like how I define it (N x N array).  But when I include
> the optimization and print what I pass from the function before the code
> crashes, it no longer looks like how I define it (i.e., 1 x more then N
> array).  Which is why I think I get the shape error.

I haven't run your code but the failure is proabbly to passing the wrong
arguments to fmin_cobyla. Usually the scalar minimizers take a 1-D array as
input and expect the function to be minimized to return a single scalar value.
The constraints functions too have to return a single value > 0 if the
constraint is fulfilled, < 0 if not.
You get a flattened version of your arrays by calling numpy.ravel(). Later you
may want to reshape it too its orginal shape using numpy.reshape().
Modify your script and try again, if it still doesn't work come back here again.

Some days ago I posted an example using fmin_cobyla to the list. Have a look at
that, too.

Regards, Christian


More information about the SciPy-user mailing list