this SO post은 네임 스페이스 충돌이이 오류의 원인 중 하나라고 읽었습니다. 나는이 오류에 자주 빠지다. 그래서, 정확히 을 배우고 싶습니다. 정확히 여기서 어떻게됩니까? 도서관에서 기대할 수있는 것은 무엇입니까?sympy AttributeError : 'Pow'객체에 'sin'속성이 없습니다.
EDIT : fun = lambda x: 4*x*(np.sin(x**2) - 3)*np.cos(x**2)
은 테스트 케이스에서 비롯되었으므로 실제로는 '재미'기능으로 사용하도록되어 있습니다. 해당 정보가 누락되어 죄송합니다. 이 제약을 존중하면서 친절하게 토론하십시오.
EDIT2 : 전체 스크립트가 아니라 코드를 재생산하는 중 오류가 발생했습니다. 작업은 섭동 Δ = 10 -8의 순방향 근사법을 사용하여 수위가 낮은 배열을 평가할 수있는 입력 함수의 미분을 계산하는 것입니다.
코드 :
import sympy
import numpy as np
# TESTING...
x = sympy.Symbol('x')
fun = lambda x: 4*x*(np.sin(x**2) - 3)*np.cos(x**2)
print fun
h = 10e-8 #perturbation
print fun(x)
print fun(x+h)
df = (fun(x+h) - fun(x))/h
print "diff is:", df
오류 : 당신이 sympy.sin
/cos
대신 np.sin
/cos
사용하도록되어 있습니다
<function <lambda> at 0x000000001068E2E8>
Traceback (most recent call last):
File "<ipython-input-75-0582d8ebb11b>", line 1, in <module>
runfile('D:/test_hw3.py', wdir='D:')
File "D:\anaconda\lib\site-packages\spyder\utils\site\sitecustomize.py", line 866, in runfile
execfile(filename, namespace)
File "D:\anaconda\lib\site-packages\spyder\utils\site\sitecustomize.py", line 87, in execfile
exec(compile(scripttext, filename, 'exec'), glob, loc)
File "D:/test_hw3.py", line 23, in <module>
print fun(x)
File "D:/test_hw3.py", line 20, in <lambda>
fun = lambda x: 4*x*(np.sin(x**2) - 3)*np.cos(x**2)
AttributeError: 'Pow' object has no attribute 'sin'
편집 내용에 대한 답변을 검토해주십시오. 감사. – devautor
@devautor 정말로 sympy를 사용해야합니까? – kennytm
예, 있습니다. 대안이 있습니까? [내 요구 사항으로 인해이 작업을 수행 할 수는 없지만] – devautor