Thank you very much :)
在2022年5月20日星期五 UTC+2 14:47:26<[email protected]> 写道:
> Thanks to Python’s function definition facilities, you can collect your
> arguments as a list and use them as such in your function definition :
>
> >>> from sympy import symbols
> >>> X=symbols("x:5") ; X
> (x0, x1, x2, x3, x4)
> >>> def foo(*u): return "I got %d arguments."%len(u)
> ...
> >>> foo(X) # Call foo with the single argument X
> 'I got 1 arguments.'
> >>> foo(*X) # Call fo with the LIST of arguments (x0,...,x4)
> 'I got 5 arguments.'
>
> You can also have fixed arguments before the list argument :
>
> >>> def bar(u, *v): return "u=%s, v=%s"%(u, v)
> ...
> >>> bar(*X)
> 'u=x0, v=(x1, x2, x3, x4)'
>
> HTH,
>
> Le vendredi 20 mai 2022 à 07:35:57 UTC+2, [email protected] a écrit :
>
>> Hi,
>> I am a new hand in sympy. I have some questions when I using it. Could
>> you please help me?
>>
>> When I use "x = symbols('x:(n+1)')" to claim (n+1) variables, after the
>> calculations, I can get the results represented by x0, x1, x2,...xn, i.e.,
>> f(x0, x1, ..., xn), where n can change from time to time.
>> Now, I have several sets of input data, and I want to know the results of
>> the calculated function, i.e., f(input), where each set of input data has n
>> elements.
>> I am trying to convert the f(x0, x1, ..., xn) by using lambdify. For
>> example, I can only do obj = lambdify(x, f(x[0], x[1], x[2], ..., x[n]))
>> rather than lambdify(x, f(x0, x1, ..., xn)).
>> How can I use the previous calculated f(x0, x1, ..., xn) in lambdify
>> directly?
>>
>> In addition, when I calculate the result, I can only do obj(input[0],
>> input[1], ..., input[n]), can I read the input array directly, i.e.,
>> obj(input)?
>>
>> Thanks for your time.
>>
>> Best,
>> Junjie
>>
>>
>
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/sympy/f6e08d4f-3c5c-462e-aa76-71e83313db32n%40googlegroups.com.