Lambdify не работает с производной конъюгата.Python

Программы на Python
Ответить
Anonymous
 Lambdify не работает с производной конъюгата.

Сообщение Anonymous »

У меня есть очень уродливые символические функции, над которыми я хотел бы выполнить некоторые операции, а затем лямбдировать их. Среди прочего мне нужно взять производную сопряженного. Моя проблема: производная и конъюгат работают отдельно, но когда я пытаюсь лямбдифицировать производную конъюгата, выдается следующая ошибка:
PrintMethodNotImplementedError: Unsupported by :
Set the printer option 'strict' to False in order to generate partially printed code.

Подробности + работающие/неработающие примеры
Вот основная функция:
import sympy as sp

a, b = sp.symbols('a b')
def myfunction(x,y):
return x + 1j * y

myfunctionval = myfunction(a,b)
myfunction_lam = sp.lambdify((a,b), myfunctionval)
print(myfunction_lam(1,2))
>> (1+2j)

Вот сопряженное:
def myfunctionConjugate(x,y):
return sp.conjugate(x + 1j * y)

myfunctionConjugateval = myfunctionConjugate(a,b)
myfunctionConjugate_lam = sp.lambdify((a,b), myfunctionConjugateval)
print(myfunctionConjugate_lam(1,2))
>> (1-2j)

Вот производная:
def myfunctionDerivative(x,y):
return sp.diff(x + 1j * y, x)

myfunctionDerivativeval = myfunctionDerivative(a,b)
myfunctionDerivative_lam = sp.lambdify((a,b), myfunctionDerivativeval)
print(myfunctionDerivative_lam(1,2))
>> 1

Вот работает сопряжение производной:
def myfunctionDerivativeConjugate(x,y):
return sp.conjugate(sp.diff(x + 1j * y,x))

myfunctionDerivativeConjugateval = myfunctionDerivativeConjugate(a,b)
myfunctionDerivativeConjugate_lam = sp.lambdify((a,b), myfunctionDerivativeConjugateval)
print(myfunctionDerivativeConjugate_lam(1,2))
>> 1

Вот производная от конъюгата, которая НЕ работает:
def myfunctionConjugateDerivative(x,y):
return sp.diff(sp.conjugate(x + 1j * y),x)

myfunctionConjugateDerivativeval = myfunctionConjugateDerivative(a,b)
myfunctionConjugateDerivative_lam = sp.lambdify((a,b), myfunctionConjugateDerivativeval)
myfunctionConjugateDerivative_lam(1,2)

И выдает мне эту ошибку:
---------------------------------------------------------------------------
PrintMethodNotImplementedError Traceback (most recent call last)
/tmp/ipykernel_13914/1657192206.py in
3
4 myfunctionConjugateDerivativeval = myfunctionConjugateDerivative(a,b)
----> 5 myfunctionConjugateDerivative_lam = sp.lambdify((a,b), myfunctionConjugateDerivativeval)
6 myfunctionConjugateDerivative_lam(1,2)

~/anaconda3/lib/python3.9/site-packages/sympy/utilities/lambdify.py in lambdify(args, expr, modules, printer, use_imps, dummify, cse, docstring_limit)
878 else:
879 cses, _expr = (), expr
--> 880 funcstr = funcprinter.doprint(funcname, iterable_args, _expr, cses=cses)
881
882 # Collect the module imports from the code printers.

~/anaconda3/lib/python3.9/site-packages/sympy/utilities/lambdify.py in doprint(self, funcname, args, expr, cses)
1169 funcbody.append('{} = {}'.format(self._exprrepr(s), self._exprrepr(e)))
1170
-> 1171 str_expr = _recursive_to_string(self._exprrepr, expr)
1172
1173 if '\n' in str_expr:

~/anaconda3/lib/python3.9/site-packages/sympy/utilities/lambdify.py in _recursive_to_string(doprint, arg)
964
965 if isinstance(arg, (Basic, MatrixBase)):
--> 966 return doprint(arg)
967 elif iterable(arg):
968 if isinstance(arg, list):

~/anaconda3/lib/python3.9/site-packages/sympy/printing/codeprinter.py in doprint(self, expr, assign_to)
170 self._number_symbols = set()
171
--> 172 lines = self._print(expr).splitlines()
173
174 # format the output

~/anaconda3/lib/python3.9/site-packages/sympy/printing/printer.py in _print(self, expr, **kwargs)
329 printmethod = getattr(self, printmethodname, None)
330 if printmethod is not None:
--> 331 return printmethod(expr, **kwargs)
332 # Unknown object, fall back to the emptyPrinter.
333 return self.emptyPrinter(expr)

~/anaconda3/lib/python3.9/site-packages/sympy/printing/codeprinter.py in _print_not_supported(self, expr)
580 def _print_not_supported(self, expr):
581 if self._settings.get('strict', False):
--> 582 raise PrintMethodNotImplementedError("Unsupported by %s: %s" % (str(type(self)), str(type(expr))) + \
583 "\nSet the printer option 'strict' to False in order to generate partially printed code.")
584 try:

PrintMethodNotImplementedError: Unsupported by :
Set the printer option 'strict' to False in order to generate partially printed code.



Подробнее здесь: https://stackoverflow.com/questions/792 ... -conjugate
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Python»