[SciPy-user] optimize.fsolve

Ryan Krauss ryanfedora at comcast.net
Thu Aug 18 23:42:08 CDT 2005


Without having to do the unpacking manually you can also do this:

In [12]: def myfunc(x,y,z):return x+y+z
    ....:

In [13]: myargs=(3,5)

In [14]: myfunc(2,*myargs)
Out[14]: 10

(I was just reading in "Python in a Nutshell" tonight about how *seq can 
  be used for positional arguments and **dict can be used for keyword 
arguments and Python will unpack them for you).

Christian Kristukat wrote:
> Howey, David A wrote:
> 
>> thanks for all your help Ryan and Brett.
>>
>> I have now got fsolve working in my code. You won't believe how 
>> overjoyed I am!!! (the simple things in life, eh..)
>>
>> one more general python question relating to parameter passing. With 
>> routines like fsolve, the additional arguments for the user-defined 
>> function are passed in in a tuple, eg
>> args = (80000, 80000, 12.7)
>>
>> is it possible to do a hack to call the function directly, eg 
>> something like
>> answer = myfunc(x, args)
> 
> 
> def myfunc(x, *args):
>     arg1,arg2 = args
>     ...
> 
> myfunc(*(100,-3))
> 
> Regards, Christian
> 
> _______________________________________________
> SciPy-user mailing list
> SciPy-user at scipy.net
> http://www.scipy.net/mailman/listinfo/scipy-user
> 



More information about the SciPy-user mailing list