TypeError:无法获取函数签名

时间:2014-07-17 21:20:06

标签: python

我使用python-iminuit来最小化变量。我的代码如下: -


     from iminuit import describe,Minuit

     In [32]: class test:
                def f(x,y):
                  return x*y
     In [32]: ff=test()
     In [33]: m=Minuit(ff.f(1,1),x=2,error_x=.3,limit_(1,5),y=2,error_y=.3,limit_y(1,5))
     In [34]: describe(f)
     -----------------------------------------------------------------------------------
     TypeError                                 Traceback (most recent call last)
     <ipython-input-34-869682646e5a> in <module>()
     ----> 1 describe(f)
     /usr/local/lib/python2.7/dist-packages/iminuit/util.pyc in describe(f, verbose)
     161         :ref:`function-sig-label`
     162     """
     --> 163     return better_arg_spec(f, verbose)
     164 
     165 

     /usr/local/lib/python2.7/dist-packages/iminuit/util.pyc in better_arg_spec(f,verbose)
      151             print "fail parsing __doc__"
      152 
      --> 153     raise TypeError("Unable to obtain function signature")
      154     return None
      155 

      TypeError: Unable to obtain function signature

我是python的新手。我不明白它的意思。任何人都可以解释这个错误的原因是什么?

1 个答案:

答案 0 :(得分:0)

您的代码示例包含一些错误,但您并没有真正说出您想要做的事情。假设您想要使用iminuit(x, y)f(x, y) = x * y范围内找到函数x = (1, 5)的最小y = (1, 5)点,这是如何做到的:< / p>

from iminuit import Minuit

def f(x, y):
    return x * y

m = Minuit(f, pedantic=False, print_level=0,
           x=2, limit_x=(1,5),
           y=2, limit_y=(1,5))

_ = m.migrad()  # run the minimizer
print(m.values)  # show the result

这给出了一个非常接近真实解(x, y) = (1, 1)的结果:

>>> print(m.values)  # show the result
{'y': 1.0000000000293232, 'x': 1.0000000000293232}