这是您的代码的略微修改版本(如下):它看起来像一个错误。请注意,腌制 lambda 表达式会破坏原始的符号表达式对象!
我是dill
作者。我建议将它作为一个sympy
github 问题发布——如果你把它作为一个dill
问题发布,我会深入研究它,然后将它放到sympy
.
>>> import sympy as sp
>>> x,y = sp.symbols('x,y')
>>> f_ex = 2*x**2 + 2*x*y
>>> f_la = sp.lambdify((x,y),f_ex)
>>> f_ex
2*x**2 + 2*x*y
>>> import dill
>>> dill.settings['recurse'] = True
>>> la = dill.loads(dill.dumps(f_la))
>>> la
<function <lambda> at 0x10b4ed668>
>>> f_ex
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sympy/core/basic.py", line 392, in __repr__
return sstr(self, order=None)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sympy/printing/str.py", line 748, in sstr
s = p.doprint(expr)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sympy/printing/printer.py", line 233, in doprint
return self._str(self._print(expr))
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sympy/printing/printer.py", line 257, in _print
return getattr(self, printmethod)(expr, *args, **kwargs)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sympy/printing/str.py", line 51, in _print_Add
terms = self._as_ordered_terms(expr, order=order)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sympy/printing/printer.py", line 271, in _as_ordered_terms
return expr.as_ordered_terms(order=order)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sympy/core/expr.py", line 888, in as_ordered_terms
terms, gens = self.as_terms()
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sympy/core/expr.py", line 920, in as_terms
coeff = complex(coeff)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sympy/core/expr.py", line 229, in __complex__
result = self.evalf()
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sympy/core/evalf.py", line 1377, in evalf
prec = dps_to_prec(n)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/mpmath/libmp/libmpf.py", line 67, in dps_to_prec
return max(1, int(round((int(n)+1)*3.3219280948873626)))
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/fromnumeric.py", line 2293, in amax
out=out, **kwargs)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/_methods.py", line 26, in _amax
return umr_maximum(a, axis, None, out, keepdims)
ValueError: 'axis' entry is out of bounds