我试图对一些计算的特征值进行lambdify,但我得到了以下错误。
File "<string>", line 1, in <lambda>
AttributeError: 'Symbol' object has no attribute 'sqrt'为了避免名称空间冲突(在本文的What causes this error (AttributeError: 'Mul' object has no attribute 'cos') in Python?中解释),我使用了以下导入命令而不是from sympy import *
import sympy as sp
import numpy as np
def calculate_general_eigenvalues():
Y, Z = sp.symbols("Y,Z")
Rzy = sp.symbols("Rzy", positive=True)
eigenvalues = [Y + Z,Rzy*Y + sp.sqrt(Rzy*Z)]
print("eigenvalues of the system ")
print(eigenvalues[0])
print(eigenvalues[1])
lam1 = sp.lambdify((Y,Z), eigenvalues[0] ,modules=['numpy'])
lam2 = sp.lambdify((Y,Z), eigenvalues[1] ,modules=["numpy", {'sqrt': np.sqrt}])
print(lam1(1,1))
print(lam2(1,1))
return (lam1,lam2)
l1,l2 = calculate_general_eigenvalues()我还在这里发现了第二个提示(Python: SymPy lambdify abs for use with NumPy),因为它们包含命令lambdify(x, f(x), ["numpy", {'Abs': numpy.abs}]),但如您所见,它在我的代码中不起作用
我如何解决我的问题?
https://stackoverflow.com/questions/44266672
复制相似问题