I have read this SO post which says namespace conflict is one reason for this error. I am falling to this error frequently. So, I'd like to learn what exactly is happening here? What is expected by the library?
EDIT: fun = lambda x: 4*x*(np.sin(x**2) - 3)*np.cos(x**2)
comes from a test case, so practically I am bound to use it as function 'fun'. Sorry for missing that information. Kindly discuss respecting this constraint.
EDIT2: This is an error reproducing code, not the full script. Task is to calculate differentiation of an input function that can evaluate numpy arrays by using a forward difference approximation with a perturbation ∆=10 −8.
Code:
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
Error:
<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 runfileexecfile(filename, namespace)File "D:\anaconda\lib\site-packages\spyder\utils\site\sitecustomize.py", line 87, in execfileexec(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'