[SciPy-user] numpy.asarray Numeric.asarray, fmin_* return type
Steve Schmerler
elcorto at gmx.net
Tue Jan 24 07:23:10 EST 2006
Steve Schmerler wrote:
> Hi
>
> Using optimize.fmin_powell from a recent svn build with the initial
> guess x0 being a scalar I get this error:
>
> Traceback (most recent call last):
> File "trans.py", line 151, in ?
> tau = fmin_powell(func, tau_start)
> File "/usr/lib/python2.3/site-packages/scipy/optimize/optimize.py",
> line 1453, in fmin_powell
> N = len(x)
> TypeError: len() of unsized object
>
> where x = asarray(x0). Comparing numpy's and Numeric's asarray I found
>
> ===================================================================================
> In [8]: import numpy as nu
>
> In [9]: import Numeric as NU
>
> In [10]: x = nu.asarray([1,2]); len(x)
> Out[10]: 2
>
> In [11]: y = NU.asarray([1,2]); len(y)
> Out[11]: 2
>
> In [12]: x = nu.asarray(3); len(x)
> ---------------------------------------------------------------------------
> exceptions.TypeError Traceback (most
> recent call last)
>
> /home/elcorto/<console>
>
> TypeError: len() of unsized object
>
> In [13]: y = NU.asarray(3); len(y)
> Out[13]: 1
>
> ===================================================================================
>
OK an easy workarround is to provide "scalar" start values as x =
array([x0]) instead of just x0, then len(x) = 1.
(providing x0 as it is (scalar) worked for me with scipy 0.3.2)
But another thing:
fmin, fmin_cg and fmin_bfgs (I haven't tried the others) return
<type 'numpy.ndarray'> when the initial guess is of the same type (i.e.
array([x0]) which seems reasonable. Unfortunately fmin_powell returns
<type 'float64_arrtype'> in this case.
cheers,
steve
More information about the SciPy-User
mailing list