【问题标题】:How do I add "args=(...)" into arguments of my own function?如何将“args=(...)”添加到我自己函数的参数中?
【发布时间】:2018-04-25 10:30:26
【问题描述】:

在scipy中有一个函数quad():

quad(integrand, 0, 1, args=(a,b))

我有自己的函数来使用 gauss legendgre 求积积分,当我将不同的函数与参数集成时,我有点厌倦了添加它们。所以问题是:

有没有办法将参数args=(...) 添加到我自己函数的参数中?

【问题讨论】:

    标签: python numpy scipy arguments numerical-methods


    【解决方案1】:

    当然,

    def my_function(value1, value2, value3, args=(0,0)):
        print(value1, value2, value3, args)
    
    # call with only 3 values
    # it will use args=(0,0) as default
    my_function(1,2,3)
    
    # call with 3 values and args
    my_function(4,5,6, args=(7,8))
    

    输出:

    1 2 3 (0, 0)
    4 5 6 (7, 8)
    

    【讨论】:

      猜你喜欢
      • 2018-10-21
      • 1970-01-01
      • 1970-01-01
      • 2018-01-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-12
      • 1970-01-01
      相关资源
      最近更新 更多