How to pass arguments as a tuple in odeint?

I wanted to use odeint scipy with function

def func(y,t,a=123,b=456)

then use it like

odeint(func,y0,t)

If I want to change the values โ€‹โ€‹of a and b using args

odeint(func,y0,t,args=(a=1,b=2))

He complains that arguments are not tuples. This can be a very elementary question, how do I pass the keyword arguments into a tuple?

odeint(func,y0,t,args=...?)
+4
source share
2 answers

You just need to delete the assignments in order to make a legal tuple:

odeint(func,y0,t,args=(123, 456))

Here is another answer with an example of calling odeint with arguments.

+1
source

Create a list for the arguments:

list1 = ['a', 'b', 'c']

Then pass it with the prefix '*':

odeint(func, y0, t, *list1)

Which is equal to:

odeint(func, y0, t, a, b, c)
-1
source

Source: https://habr.com/ru/post/1621676/


All Articles